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

inbound stream deduplication #396

Merged
merged 3 commits into from
Jan 12, 2021
Merged

inbound stream deduplication #396

merged 3 commits into from
Jan 12, 2021

Conversation

vyzo
Copy link
Collaborator

@vyzo vyzo commented Jan 12, 2021

This adds deduplication for inbound pubsub streams so that we always have only a single inbound stream from a peer; last one wins.

@vyzo vyzo requested a review from raulk January 12, 2021 13:17
other, dup := p.inboundStreams[peer]
if dup {
log.Debugf("duplicate inbound stream from %s; resetting other stream", peer)
other.Reset()
Copy link
Member

Choose a reason for hiding this comment

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

Does the muxer guarantee that an outstanding read from this stream will error out immediately as soon as we reset it? Can't remember.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't really know, but it shouldn't matter much. As long as it happens promptly enough we should be fine.

comm.go Outdated
Comment on lines 69 to 73
p.inboundStreamsMx.Lock()
if p.inboundStreams[peer] == s {
delete(p.inboundStreams, peer)
}
p.inboundStreamsMx.Unlock()
Copy link
Member

Choose a reason for hiding this comment

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

Probably should put this in a defer, so that it's also run on other return paths.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, there are no other relevant return code paths. The only other return is in the context cancellation case, where we don't care because we are shutting down.
Having said that, it is probably cleaner to do it in a defer so why not.

@vyzo vyzo merged commit 9e129db into master Jan 12, 2021
@vyzo vyzo deleted the feat/inbound-stream-dedup branch January 12, 2021 15:18
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.

2 participants