From dea75a4211b0f41f54b97dd50d254ab2d1ef3be1 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 19 Aug 2022 20:43:15 +0300 Subject: [PATCH] network: wait for the relayer thread to finish on shutdown Unsubscribe and drain first, then return from the Shutdown method. It's important wrt to subsequent chain shutdown process (normally it's closed right after the network server). --- pkg/network/server.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/network/server.go b/pkg/network/server.go index 1779f7b70..00cfe4764 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -121,6 +121,7 @@ type ( register chan Peer unregister chan peerDrop quit chan struct{} + relayFin chan struct{} transactions chan *transaction.Transaction @@ -170,6 +171,7 @@ func newServerFromConstructors(config ServerConfig, chain Ledger, stSync StateSy id: randomID(), config: chain.GetConfig(), quit: make(chan struct{}), + relayFin: make(chan struct{}), register: make(chan Peer), unregister: make(chan peerDrop), txInMap: make(map[util.Uint256]struct{}), @@ -273,6 +275,7 @@ func (s *Server) Shutdown() { s.notaryRequestPool.StopSubscriptions() } close(s.quit) + <-s.relayFin } // AddService allows to add a service to be started/stopped by Server. @@ -1433,6 +1436,7 @@ drainBlocksLoop: } } close(ch) + close(s.relayFin) } // verifyAndPoolTX verifies the TX and adds it to the local mempool.