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

p2p: seed_mode sometimes fails to send pexAddrsMessage before disconnecting gracefully #2092

Closed
ebuchman opened this issue Jul 27, 2018 · 2 comments
Labels
C:p2p Component: P2P pkg T:bug Type Bug (Confirmed)
Milestone

Comments

@ebuchman
Copy link
Contributor

When SeedMode is true, the PexReactor sends a batch of addresses and calls StopPeerGracefully. It seems sometimes the peer ends up disconnecting before these messages are delivered, which makes it difficult for a new node to join the network.

It looks like we don't call .flush() in the MConnection.OnStop(). I tried adding that on the seed node, but even still the new node sometimes fails to receive any addresses from the seed.

@ebuchman ebuchman added T:bug Type Bug (Confirmed) C:p2p Component: P2P pkg labels Jul 27, 2018
@ebuchman ebuchman added this to the launch milestone Jul 27, 2018
@phymbert
Copy link
Contributor

phymbert commented Oct 6, 2018

@ebuchman StopPeerGracefully yet implemented. bcStatusResponseMessage is processed before pexAddrsMessage. Connection is closed by seed peer before pexAddrsMessage arrived in pex channel...

I did a dirty fix that seem to work in pex_reactor.go:

if r.config.SeedMode {
			r.SendAddrs(src, r.book.GetSelectionWithBias(biasToSelectNewPeers))
			go func() {
				time.Sleep(5 * time.Second)
				r.Switch.StopPeerGracefully(src)
			}()
		}

I will try to submit a PR to handle shutdown gracefully properly.

ebuchman added a commit that referenced this issue Nov 11, 2018
In seed mode, we call StopPeer immediately after Send.
Since flushing msgs to the peer happens in the background,
the peer connection is often closed before the messages are
actually sent out. This allows all msgs to first be written and flushed out
on the conn before it is closed.
ebuchman added a commit that referenced this issue Nov 11, 2018
In seed mode, we call StopPeer immediately after Send.
Since flushing msgs to the peer happens in the background,
the peer connection is often closed before the messages are
actually sent out. This allows all msgs to first be written and flushed out
on the conn before it is closed.
ebuchman added a commit that referenced this issue Nov 11, 2018
In seed mode, we call StopPeer immediately after Send.
Since flushing msgs to the peer happens in the background,
the peer connection is often closed before the messages are
actually sent out. The new FlushStop method allows all msgs
to first be written and flushed out on the conn before it is closed.
@ebuchman
Copy link
Contributor Author

@phymbert you solution was implemented in #2797. But see #2802 for my attempt to do it more correctly.

ebuchman added a commit that referenced this issue Nov 16, 2018
* p2p/conn: FlushStop. Use in pex. Closes #2092

In seed mode, we call StopPeer immediately after Send.
Since flushing msgs to the peer happens in the background,
the peer connection is often closed before the messages are
actually sent out. The new FlushStop method allows all msgs
to first be written and flushed out on the conn before it is closed.

* fix dummy peer

* typo

* fixes from review

* more comments

* ensure pex doesn't call FlushStop more than once

FlushStop is not safe to call more than once,
but we call it from Receive in a go-routine so Receive
doesn't block.

To ensure we only call it once, we use the lastReceivedRequests
map - if an entry already exists, then FlushStop should already have
been called and we can return.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:p2p Component: P2P pkg T:bug Type Bug (Confirmed)
Projects
None yet
Development

No branches or pull requests

2 participants