cmd, node, p2p/simulations: fix node account manager leak (#19004)
* node: close AccountsManager in new Close method * p2p/simulations, p2p/simulations/adapters: handle node close on shutdown * node: move node ephemeralKeystore cleanup to stop method * node: call Stop in Node.Close method * cmd/geth: close node.Node created with makeFullNode in cli commands * node: close Node instances in tests * cmd/geth, node: minor code style fixes * cmd, console, miner, mobile: proper node Close() termination
This commit is contained in:
committed by
Péter Szilágyi
parent
81801ccc2b
commit
26aea73673
23
node/node.go
23
node/node.go
@ -121,6 +121,29 @@ func New(conf *Config) (*Node, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Close stops the Node and releases resources acquired in
|
||||
// Node constructor New.
|
||||
func (n *Node) Close() error {
|
||||
var errs []error
|
||||
|
||||
// Terminate all subsystems and collect any errors
|
||||
if err := n.Stop(); err != nil && err != ErrNodeStopped {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
if err := n.accman.Close(); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
// Report any errors that might have occurred
|
||||
switch len(errs) {
|
||||
case 0:
|
||||
return nil
|
||||
case 1:
|
||||
return errs[0]
|
||||
default:
|
||||
return fmt.Errorf("%v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
// Register injects a new service into the node's stack. The service created by
|
||||
// the passed constructor must be unique in its type with regard to sibling ones.
|
||||
func (n *Node) Register(constructor ServiceConstructor) error {
|
||||
|
Reference in New Issue
Block a user