peer: drain chans before exiting peerHandler

Also disconnect the failed peer to allow the peerDoneHandler goroutine
to exit, instead of hanging around. Fixes #583.
This commit is contained in:
Javed Khan 2015-12-16 23:49:27 +05:30
parent e24fe94f58
commit 7996eb1f9d

View file

@ -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")
}