node: stop p2p.Server before stopping services

This prevents printing of a gazillion error messages which
result from connections trying to interact with stopped core
services.
This commit is contained in:
Felix Lange 2016-01-29 11:27:52 +01:00
parent 528dcc3814
commit d2a437ecac

View file

@ -178,25 +178,23 @@ func (n *Node) Stop() error {
n.lock.Lock() n.lock.Lock()
defer n.lock.Unlock() defer n.lock.Unlock()
// Short circuit if the node's not running
if n.server == nil { if n.server == nil {
return ErrNodeStopped return ErrNodeStopped
} }
// Otherwise terminate all the services and the P2P server too
failure := &StopError{ // Stop the server first. This will block until all connections
Services: make(map[reflect.Type]error), // are done interacting.
} n.server.Stop()
// Stop all services.
failure := &StopError{Services: make(map[reflect.Type]error)}
for kind, service := range n.services { for kind, service := range n.services {
if err := service.Stop(); err != nil { if err := service.Stop(); err != nil {
failure.Services[kind] = err failure.Services[kind] = err
} }
} }
n.server.Stop()
n.services = nil n.services = nil
n.server = nil n.server = nil
close(n.stop) close(n.stop)
if len(failure.Services) > 0 { if len(failure.Services) > 0 {
return failure return failure
} }