-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
investigation: hanging TCPSocketWrap in js-libp2p-amino-dht-bootstrapper #2537
Labels
need/triage
Needs initial labeling and prioritization
Comments
After running js-libp2p-amino-dht-bootstrapper over the weekend, starting with heapsnapshot->gc->heapsnapshot, then taking snapshots every 6 hours, and finishing this morning with heap->gc->heap, memlab gives the following result for
I don't see anything obvious here. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
related to libp2p/js-libp2p-amino-dht-bootstrapper#18 (comment)
I will be adding various observations here while looking around at connection open and close code in js-libp2p
Destroying connections on
MultiaddrConnection.close
1. timeout events not handled
js-libp2p/packages/transport-tcp/src/socket-to-conn.ts
Lines 158 to 178 in 4ad63bb
When
maConn.close
is called, we try to explicitly close a socket, handlingclose
anderror
events, but nottimeout
events which can definitely occur.From https://nodejs.org/docs/latest-v20.x/api/net.html#socketsettimeouttimeout-callback
This seems like it could easily lead to TCPSocketWrap continuing to increase.
Questions
setTimeout
again, does it still allow the callback defined at https://github.com/libp2p/js-libp2p/blob/4ad63bb79c0c2e5c670b32aa534906b923dcf150/packages/transport-tcp/src/socket-to-conn.ts#L62C1-L75C5 to trigger? (it seems like that's the intention).2. Manual
socket.destroySoon
logicjs-libp2p/packages/transport-tcp/src/socket-to-conn.ts
Lines 183 to 194 in 4ad63bb
I'm not sure if we're intentionally not using
socket.destroySoon
but AFAIK, the only thing we would be missing by switching this code tosocket.destroySoon
is thelog('%s socket drained', lOptsStr)
log line, which we could easily add up above.3. Socket
'drop'
eventjs-libp2p/packages/transport-tcp/test/max-connections.spec.ts
Lines 64 to 66 in 4ad63bb
We have some tests that test our maxConnections, but we have no code that handles the
'drop'
event in https://github.com/libp2p/js-libp2p/blob/4ad63bb79c0c2e5c670b32aa534906b923dcf150/packages/transport-tcp/src/socket-to-conn.ts.Questions
drop
ped Sockets are not closed out properly?4.
Socket.unref
I don't see that we're calling
socket.unref
anywhere, and adding it kind of feels like a hack, but I think there are a few locationsmaConn.close
and others where we could callsocket.unref()
to make sure we're explicit about when the socket is no longer needed.e.g. once we call
maConn.close
and'drain'
is emitted,socket.unref()
could be safely called?Holistic Socket management
1. Transport class vs toMaConn socket event cleanup
js-libp2p/packages/transport-tcp/src/index.ts
Lines 242 to 245 in 4ad63bb
TCP Transport class cleans up events it adds to sockets, why doesn't
socket-to-conn.ts
orlistener.ts
?Questions
allEventListeners
in the TCP transport class?The text was updated successfully, but these errors were encountered: