only exit the dispatch loop if the node is closing

This commit is contained in:
StephenButtolph 2020-06-02 18:59:34 -04:00
parent 7671cab972
commit b8bd018938
3 changed files with 14 additions and 5 deletions

View File

@ -81,6 +81,7 @@ func main() {
defer node.Shutdown() defer node.Shutdown()
log.Debug("Dispatching node handlers") log.Debug("dispatching node handlers")
node.Dispatch() err = node.Dispatch()
log.Debug("dispatch returned with: %s", err)
} }

View File

@ -485,8 +485,16 @@ func (n *network) Dispatch() error {
for { for {
conn, err := n.listener.Accept() conn, err := n.listener.Accept()
if err != nil { if err != nil {
n.stateLock.Lock()
closed := n.closed
n.stateLock.Unlock()
if closed {
return err return err
} }
n.log.Debug("error during server accept: %s", err)
continue
}
go n.upgrade(&peer{ go n.upgrade(&peer{
net: n, net: n,
conn: conn, conn: conn,

View File

@ -195,7 +195,7 @@ func (i *insecureValidatorManager) Disconnected(vdrID ids.ShortID) bool {
// Dispatch starts the node's servers. // Dispatch starts the node's servers.
// Returns when the node exits. // Returns when the node exits.
func (n *Node) Dispatch() { func (n *Node) Dispatch() error {
// Add bootstrap nodes to the peer network // Add bootstrap nodes to the peer network
for _, peer := range n.Config.BootstrapPeers { for _, peer := range n.Config.BootstrapPeers {
if !peer.IP.Equal(n.Config.StakingIP) { if !peer.IP.Equal(n.Config.StakingIP) {
@ -205,7 +205,7 @@ func (n *Node) Dispatch() {
} }
} }
n.Net.Dispatch() return n.Net.Dispatch()
} }
/* /*