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: emiting of peer:disconnect when a connection is still open (#301) #307

Closed
wants to merge 1 commit into from

Conversation

nikor
Copy link
Contributor

@nikor nikor commented Jan 7, 2019

This should fix #301

Copy link
Contributor

@jacobheun jacobheun left a comment

Choose a reason for hiding this comment

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

Thanks for submitting a PR for this! Can you add tests to verify the fix?

@nikor
Copy link
Contributor Author

nikor commented Jan 8, 2019

Okay. I messed up. There is only a problem if there is two separate muxed connection to the same node (for instance two tcp connections with spdy). And that will only happen under the very specific test conditions I had.
Sorry about that.
The good news is that no patch is needed :)

@jacobheun
Copy link
Contributor

Parallel dials will cause this as well, for example these new tests on switch: https://github.com/libp2p/js-libp2p-switch/pull/298/files#diff-063533a50438d54e519fdd9f9161bc82.

I think my main concern here is that the peer will always be in the peerBook, so we'll never fire the the disconnect event. I think we may need to actually check for connections with the PeerId via https://github.com/libp2p/js-libp2p-switch/blob/v0.41.4/src/connection/manager.js#L62.

@nikor
Copy link
Contributor Author

nikor commented Jan 10, 2019

The more i look at the connections management the more confused i get :)

From what i can see, the connections object (https://github.com/libp2p/js-libp2p-switch/blob/v0.41.4/src/connection/manager.js#L22) only contains the real connection that are being used for multiplexing.
So if libp2p is running without muxing, the connections object is always empty and hangup does not work (https://github.com/nikor/js-libp2p-test/blob/master/test1.js). Is that expected behavior?

It also seems like the connection is not removed from the object if the other end closes it (https://github.com/nikor/js-libp2p-test/blob/master/test2.js). But i think that is a seperate issue.

But about the current problem. I can only get libp2p to emit 'peer:disconnect' if i do a hangup, but that is expected behavior. How do i close only inbound or outbound connections?

@jacobheun
Copy link
Contributor

The more i look at the connections management the more confused i get :)

Yeah, the connection logic is pretty confusing. It's getting better, but still has a ways to go.

So if libp2p is running without muxing, the connections object is always empty and hangup does not work (https://github.com/nikor/js-libp2p-test/blob/master/test1.js). Is that expected behavior?

No, hangup should work, it's just not in there yet as the focus has been primarily on muxed connections because they're a more efficient use of connections. We do need to do this though, to avoid leaking connections.

But about the current problem. I can only get libp2p to emit 'peer:disconnect' if i do a hangup, but that is expected behavior. How do i close only inbound or outbound connections?

That is being done here, libp2p/js-libp2p-switch#298. The work is done, but there is a bug in the libp2p tests I haven't been able to look at yet.

@jacobheun
Copy link
Contributor

The connection manager in the switch now keeps track of the connections and will only emit when all connections to that peer have been removed, https://github.com/libp2p/js-libp2p-switch/blob/v0.42.11/src/connection/manager.js#L86.

@jacobheun jacobheun closed this May 17, 2019
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.

Dont emit peer:disconnect when a connection is still open
2 participants