Skip to content

Conversation

@Freezystem
Copy link
Contributor

@Freezystem Freezystem commented Sep 1, 2025

I removed event listener declaration from the connection script to avoid memory leaks.

Instanciating several services including the moleculer-db-adapter-mongoose mixin will result on 3 event listeners declared by services, thus, node is emitting a warning on possible memory leak.

It's better to let the user instanciate his own event listener to avoid this issue.

Here is the warnings I got:
image

fixes #262

I removed event listener declaration from the connection script to avoid memory leaks.
Instanciating several services including the `moleculer-db-adapter-mongoose` mixin will result on 3 event listeners declared by services, thus, node is emitting a warning on possible memory leak.
It's better to let the user instanciate his own event listener to avoid this issue
@icebob
Copy link
Member

icebob commented Sep 10, 2025

I mean the warning, but it won't cause memory leak issue because the number of loaded services doesn't change in normal production env, only in development. But it can cause issue if you don't see the connection errors on the console, just that the broker is not started and waiting for something but no any information.

@Freezystem
Copy link
Contributor Author

I would argue that users may define their listeners by themselves if they need them to log something.
The problem is that I've tried to remove them manually and it doesn't work.
I've tried to remove them from a lot of place like created() or started() and even in the stopped() hooks but I always get those warnings.
Do you know a way to do it properly ?
We can also put the instantiation of these listeners behind an option. 'on' by default for legacy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants