From 7996eb1f9deee90a070e2d6455c71bd5738192f5 Mon Sep 17 00:00:00 2001 From: Javed Khan Date: Wed, 16 Dec 2015 23:49:27 +0530 Subject: [PATCH] peer: drain chans before exiting peerHandler Also disconnect the failed peer to allow the peerDoneHandler goroutine to exit, instead of hanging around. Fixes #583. --- server.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/server.go b/server.go index de1c584e70..8d62f148ef 100644 --- a/server.go +++ b/server.go @@ -1494,7 +1494,7 @@ func (s *server) peerConnHandler(sp *serverPeer) { err := s.establishConn(sp) if err != nil { srvrLog.Debugf("Failed to connect to %s: %v", sp.Addr(), err) - s.donePeers <- sp + sp.Disconnect() } } @@ -1730,6 +1730,23 @@ out: } s.blockManager.Stop() s.addrManager.Stop() + + // Drain channels before exiting so nothing is left waiting around + // to send. +cleanup: + for { + select { + case <-s.newPeers: + case <-s.donePeers: + case <-s.peerHeightsUpdate: + case <-s.relayInv: + case <-s.broadcast: + case <-s.wakeup: + case <-s.query: + default: + break cleanup + } + } s.wg.Done() srvrLog.Tracef("Peer handler done") }