holepunchto / hyperswarm

A distributed networking stack for connecting peers.
https://docs.holepunch.to
MIT License
1.04k stars 84 forks source link

fix: use 'once' for socket close event handler #64

Closed arlac77 closed 2 years ago

arlac77 commented 3 years ago

Prevent registering several close handlers by using 'once'

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [Socket]. Use emitter.setMaxListeners() to increase limit
 at _addListener (events.js:389:17)
 at Socket.addListener (events.js:405:10)
 at Socket.Readable.on (_stream_readable.js:852:35)
 at /services/system-dashboard/node_modules/hyperswarm/swarm.js:110:14
 at Socket.onconnect (/services/system-dashboard/node_modules/@hyperswarm/network/index.js:95:7)
 at Socket.emit (events.js:314:20)
 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1132:10)
Possible EventEmitter memory leak detected. 11 close listeners added to [Socket]. Use emitter.setMaxListeners() to increase limit
mafintosh commented 3 years ago

What is this fixing?

arlac77 commented 3 years ago

My hope was that it prevents excessive adding of 'close' event handlers. I will try to further isolate the problem so than it can be reproduced (currently i do not understand the exact circumstances)

mafintosh commented 3 years ago

Shouldn’t make a difference wheather it’s once or on here as the socket is not reused, but let me know if you can make a test case or similar.