Skip to content
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: dialer leaking resources after stopping #947

Merged
merged 2 commits into from
Jun 14, 2021

Conversation

vasco-santos
Copy link
Member

@vasco-santos vasco-santos commented May 27, 2021

This PR fixes the potential leaking of resources in the dialer on stop.

During the transport.dial flow, if libp2p is stopped the on going dials were being aborted. However, situations like libp2p/js-libp2p-tcp#142 were possible when a given resolvable multiaddr (dnsaddr) is being resolved before getting into the transport level. This would result in new dial attempts after stop and established connections that prevented the process from properly stop.

Unfortunately, node's dns record resolution does not allow the lookup to be abortable. As a consequence, this PR adds a competing Cancellable promise, which will be rejected in case of libp2p.stop() => dialer.destroy(). With this, the promise that would resolve the dialTarget will be rejected and the current on going dial all together.

Moreover, as described in #779 the latency monitor was not being properly closed. So, I also added start and stop functions to it (instead of the really odd pattern of starting it in the constructor).

Closes #779

@vasco-santos vasco-santos requested a review from achingbrain May 27, 2021 14:29
Copy link
Member

@achingbrain achingbrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a small enhancement to the test needed


await libp2p.stop()
await expect(dialPromise)
.to.eventually.be.rejected()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion should be be expanded to ensure the right type of error is being thrown.

@lidel lidel requested a review from achingbrain May 31, 2021 14:21
@vasco-santos vasco-santos requested a review from yusefnapora June 8, 2021 07:54
@vasco-santos vasco-santos merged commit b291bc0 into master Jun 14, 2021
@vasco-santos vasco-santos deleted the fix/dialer-leaking-resources branch June 14, 2021 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

libp2p not shutting down properly
2 participants