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

mark the peer as dead if the inbound stream closes #39

Merged
merged 3 commits into from
Oct 14, 2017
Merged

Conversation

Stebalien
Copy link
Member

fixes #38

@ghost ghost assigned Stebalien Oct 14, 2017
@ghost ghost added the in progress label Oct 14, 2017
@Stebalien
Copy link
Member Author

Technically, we may still have a connection to the peer but they're still "dead" from the perspective of pubsub (they've closed their pubsub stream to us).

@Stebalien
Copy link
Member Author

Wait before you merge this. There's an edge case when we receive a second stream from a peer and kill the first.

1. Don't hang marking a peer as dead if we're shutting down.
2. No need to "drain" the outgoing channel anymore. This may have been necessary
to prevent a deadlock where the main loop blocked on sending on sending a
message while we waited to tell the main loop that the peer was dead. However,
this is no longer an issue (we never block on sending).
@Stebalien
Copy link
Member Author

Actually, there are quite a few existing race conditions around that. I don't think there are any that can cause leaks but many that can cause two peers to fail to connect (e.g., if they both connect to each other at the same time). Really, we should support multiple connections and multiple streams to each peer.

However, IMO, that's an issue for another time (#40) and this PR should be good to go (except for the test hangs but I believe that's #22)

@Stebalien Stebalien requested a review from Kubuxu October 14, 2017 18:37
@@ -74,21 +77,16 @@ func (p *PubSub) handleSendingMessages(ctx context.Context, s inet.Stream, outgo
if !ok {
return
}
if dead {
Copy link
Member Author

Choose a reason for hiding this comment

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

Shouldn't need this anymore (I believe this existed as a hack to prevent some deadlocks but those are no longer possible).

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you are correct. This was because sends on the other end of this outgoing channel could get filled up and block the loops. All those sends are now coupled with default selects (though please double check this for me).

@Stebalien Stebalien merged commit 6d14add into master Oct 14, 2017
@ghost ghost removed the in progress label Oct 14, 2017
@Stebalien Stebalien deleted the fix/38 branch October 14, 2017 23:28
@Stebalien
Copy link
Member Author

I'll do a release once I get libp2p/go-peerstream#13 reviewed once more and merged (so I can bubble both of them up at once).

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.

Likely go routine leak of handleSendingMessages
2 participants