Closed tegefaulkes closed 7 months ago
We had a quick discussion about it. This is the one case were it's fine to have many handlers on the one event. Since we have many clients to one socket. So the solution here is to just up the limit before the warning is shown. Keep in mind that this will hide future problems. Also, I'm pretty sure using events.setMaxListeners()
will apply globally to anything that imports js-quic
as well.
This was addressed by commit d3a1d937f43d24cb065510b2abb78c9e0374630c
On reflection The solution is too global. I'm going to look into this a bit more.
Ok, so there is a way to set it specifically for an instance of EventTarget using the following.
const {
setMaxListeners,
} = require('events');
console.log(sharedSocket[_eventTarget]);
setMaxListeners(100000, sharedSocket[_eventTarget]);
I had to do a little digging to find that function.
I'll be applying it to the QUICSocket
EventTarget
.
OK, the warning limit should only be increased for the QUICSocket
EventTarget
.
Marking this as closed as per commit d5abdb2afdffbac6ea64fe7ab80d7fbe5110a7d6
I'd argue you should put that in a utility function somewhere and expose it. But also consider conditionally running that while in nodejs platform. Not sure since we would want to use in non-node platforms.
Specification
When a lot of connections are made we get the following warning
This is not strictly a problem, it's a dumb warning if we register too many handlers to a single event.
I did some digging in the code and found the cause to be us registering a once handler to
EventQUICSocketStopped
increateQUICCLient
. Normally this is not a problem unless you're using a shared socket and making many connections. Which is our normal usage inPolykey
.This is not really a bug in our usage, It should be fine to register multiple events to a single handler like this. But we need to remove the warning and I'm not sure what the best ways to go about it are. So I'm creating this issue to discuss it.
The options are
QUICSocket
calls. Same difference but the socket will need to track the clients to make calls to them. Far from ideal.NodeConnectionManager
handle the event and make calls to theQUICClients
. Then it's up to whatever manages the clients to handle the event. Meaning we depend on external usage to handle this.Any other ideas?
I've made some changes and testing in the
feature-EventTarget-leak
branchAdditional context
Tasks