Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

fix: prevent undefined error during a mutual hangup #260

Merged
merged 1 commit into from
May 31, 2018

Conversation

jacobheun
Copy link
Contributor

This resolves an issue where if connected nodes hang up at the same time, such as during testing, a muxedConnection could be deleted from the switch at the same time as it's async iteration was occurring to end those connections. This would result in an undefined error.

This PR ensures we don't attempt to close connections that have been hung up on.

You can see the passing CI build for js-libp2p that uses this branch here: https://ci.ipfs.team/blue/organizations/jenkins/libp2p%2Fjs-libp2p/detail/chore%2Fupdate-switch/4/pipeline

connects to libp2p/js-libp2p#198

src/index.js Outdated
@@ -110,6 +110,11 @@ class Switch extends EE {
this.stats.stop()
series([
(cb) => each(this.muxedConns, (conn, cb) => {
// If the connection was destroyed while we are hanging up, continue
if (conn === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

Should this check be so restrictive? Perhaps an if (conn) {...} should do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally had a more generic check if (!conn), but changed it to undefined as there shouldn't be a situation where conn is something other than undefined or an object with the muxer property. The only way it would be something other than those two options is if deletions of the muxers changes internally, or if they are overridden by another library.

I suppose the tiny performance benefit during a swarm stop isn't worth the longer term resilience of the generic check. I can update this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update pushed, this should be good to go.

Copy link
Member

@dryajov dryajov left a comment

Choose a reason for hiding this comment

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

LGTM, other than the comment I left.

@coveralls
Copy link

coveralls commented May 30, 2018

Pull Request Test Coverage Report for Build 867

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 8 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.2%) to 89.681%

Files with Coverage Reduction New Missed Lines %
../src/index.js 3 91.76%
../src/dial.js 5 88.24%
Totals Coverage Status
Change from base Build 866: -0.2%
Covered Lines: 583
Relevant Lines: 623

💛 - Coveralls

@jacobheun jacobheun merged commit 81d4394 into master May 31, 2018
@ghost ghost removed the in progress label May 31, 2018
@jacobheun jacobheun deleted the fix/swarm-stop branch May 31, 2018 19:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants