-
Notifications
You must be signed in to change notification settings - Fork 453
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
fix: close MultiaddrConnection once #2478
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but can you please add some tests to ensure there are no regressions around this in future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've suggested some improvements to the test so that it actually asserts that the socket destroyed and only once.
The problem is, it still passes even if I remove the edits to socket-to-conn.ts
so I don't think it exercises the bug that this PR is supposed to fix, though it's possible I've missed the point.
#2478 implies maconns are not being closed, rather than being closed multiple times so I guess the question is; under what circumstances are sockets not being closed?
Could you please improve the test so that it shows the bug being addressed?
|
||
// promise that is resolved when our outgoing socket is closed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a spy on .destroy()
so we can assert that the socket was only closed once:
// promise that is resolved when our outgoing socket is closed | |
// spy on `.destroy()` invocations | |
const serverSocketDestroySpy = Sinon.spy(serverSocket, 'destroy') | |
// promise that is resolved when our outgoing socket is closed |
@achingbrain thanks for the suggestions, now I improved the test and it failed on this is all about |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating the test. I wonder if we could make a further improvement as a follow up.
If two call site invoke .close
, they may perform clean up operations after the promise from that operation resolves. If it's the second invocation, as implemented the promise will resolve immediately even though the first operation may not have completed - so the socket is still open.
This will likely lead to subtle bugs that are hard to diagnose.
Instead perhaps there should be an internal deferred promise that can be returned to the second call site, and resolved by the invocation from the first. It would be rejected by the call to .abort
and the socket closed immediately if not already destroyed.
This kind of behaviour would benefit all transports so it could be pushed up in to a superclass similar to AbstractStream
and tests added to the interface suite.
Use same promise when closing`MultiaddrConnection` multiple time See #2478 (review)
Title
Close MultiaddrConnection once
Description
js-libp2p/packages/transport-tcp/src/socket-to-conn.ts
Line 177 in c5003d4
close()
again it'll run the function againNotes & open questions
this could fix #2477 see #2477 (comment)
Change checklist