network: rework shutdown sequence of Server
Close transport and disconnect peers right in the Shutdown(), so that no new
connections would be accepted and so that all the peers would be disconnected
correctly (avoiding the same deadlock as in e2116e4c3f
).
This commit is contained in:
parent
77624a8847
commit
e213e69a33
1 changed files with 5 additions and 5 deletions
|
@ -183,8 +183,12 @@ func (s *Server) Start(errChan chan error) {
|
||||||
// Shutdown disconnects all peers and stops listening.
|
// Shutdown disconnects all peers and stops listening.
|
||||||
func (s *Server) Shutdown() {
|
func (s *Server) Shutdown() {
|
||||||
s.log.Info("shutting down server", zap.Int("peers", s.PeerCount()))
|
s.log.Info("shutting down server", zap.Int("peers", s.PeerCount()))
|
||||||
s.bQueue.discard()
|
s.transport.Close()
|
||||||
s.discovery.Close()
|
s.discovery.Close()
|
||||||
|
for p := range s.peers {
|
||||||
|
p.Disconnect(errServerShutdown)
|
||||||
|
}
|
||||||
|
s.bQueue.discard()
|
||||||
close(s.quit)
|
close(s.quit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,10 +216,6 @@ func (s *Server) run() {
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case <-s.quit:
|
case <-s.quit:
|
||||||
s.transport.Close()
|
|
||||||
for p := range s.peers {
|
|
||||||
p.Disconnect(errServerShutdown)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
case p := <-s.register:
|
case p := <-s.register:
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
|
|
Loading…
Reference in a new issue