From 2b7a3a379bd7e8ad8ad3e3836556cc2a1e5b0f0d Mon Sep 17 00:00:00 2001 From: Lewis Marshall Date: Sun, 25 Jun 2017 12:29:58 +0200 Subject: [PATCH] p2p: Prevent blocking on the conn.cont channel Signed-off-by: Lewis Marshall --- p2p/server.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/p2p/server.go b/p2p/server.go index eb7c70e593..3127d5aa04 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -548,7 +548,11 @@ running: c.flags |= trustedConn } // TODO: track in-progress inbound node IDs (pre-Peer) to avoid dialing them. - c.cont <- srv.encHandshakeChecks(peers, c) + select { + case c.cont <- srv.encHandshakeChecks(peers, c): + case <-srv.quit: + break running + } case c := <-srv.addpeer: // At this point the connection is past the protocol handshake. // Its capabilities are known and the remote identity is verified. @@ -569,7 +573,11 @@ running: // The dialer logic relies on the assumption that // dial tasks complete after the peer has been added or // discarded. Unblock the task last. - c.cont <- err + select { + case c.cont <- err: + case <-srv.quit: + break running + } case pd := <-srv.delpeer: // A peer disconnected. d := common.PrettyDuration(mclock.Now() - pd.created)