libp2p handle resulting in MaxListenersExceededWarning, potentially blocking other connections in the dial queue #2749
Replies: 2 comments
-
Further investigation points to inconsistent firing of the libp2p.pubsub's subscription-change event. To replicate the problem: Clone the repo and set up the node project:
Launch the server from the command line:
Place the attached file into ./test/ and rename as lander-test.js: Launch another terminal and run the lander-test:
If you re-run the lander-test.js a few times, eventually it will eventually hang. This is because pubsub's "subscription-change" event is not fired. The problem is the event being fired/not fired is inconsistent. Because I was receiving listener warnings, I suspected that this could be the problem. Firstly, it is worth pointing out that both peers successfully connect. This can be witnessed by using the peer:connect/disconnect on both peers. The subscription-change listener is registered on line 280 in /path/to/orbit-db-pinner/node_modules/@orbitdb/core/src/sync.js. The line that calls pubsub.subscribe which should trigger the subscription-change event is line 284 in /path/to/orbit-db-pinner/node_modules/@orbitdb/core/src/sync.js. The subscribe is always successfully called on the server (pinner). However, this doesn't necessarily result in the subscription-change event being called within the client. Sometimes it fires, sometimes it doesn't. What is the best way to diagnose an event listener which inconsistently fails? [Edit] I've tracked the problem to here. It seems that sometimes the stream is not ready in time and so source is empty. Could this be related to this? |
Beta Was this translation helpful? Give feedback.
-
As suggested in the js-libp2p maintainers call, I have opened an issue. |
Beta Was this translation helpful? Give feedback.
-
We have been building an RPC server using libp2p protocols with handlers (e.g. libp2p.handle('my/protocol', ...). Clients connect and disconnect from this RPC server, each time opening a stream, transferring data then closing the stream. I have monitored the stream status and can confirm that streams are closing once data has completed transferring.
One problem I'm experiencing is the timeout of streams after repeated connections. Over time, I begin to see MaxListener warnings, which eventually leads to connection timeouts and, ultimately, the server crashing.
In particular, I'm seeing the warning:
These warnings increase in number the more times I connect a client.
However, I can't work out what is causing this issue.
I believe this is what is causing the timeouts and server crash but it is difficult to confirm. To start, I guess I could increase the max listeners to see if it delays the problem? If so, how would I implement such a fix?
The max listeners exceeded issue would indicate something else is causing problems, maybe streams left open (although monitoring them suggests they get closed once the data has been fully transferred).
[Edit]
What's interesting is I've also noticed I'm getting listener warnings for subscription-change too:
Beta Was this translation helpful? Give feedback.
All reactions