mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
p2p/simulations, p2p/simulations/adapters: handle node close on shutdown
This commit is contained in:
parent
e582efd782
commit
c7bd9ccb88
2 changed files with 13 additions and 0 deletions
|
|
@ -172,6 +172,12 @@ type SimNode struct {
|
|||
registerOnce sync.Once
|
||||
}
|
||||
|
||||
// Close closes the underlaying node.Node to release
|
||||
// acquired resources.
|
||||
func (sn *SimNode) Close() error {
|
||||
return sn.node.Close()
|
||||
}
|
||||
|
||||
// Addr returns the node's discovery address
|
||||
func (sn *SimNode) Addr() []byte {
|
||||
return []byte(sn.Node().String())
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -569,6 +570,12 @@ func (net *Network) Shutdown() {
|
|||
if err := node.Stop(); err != nil {
|
||||
log.Warn("Can't stop node", "id", node.ID(), "err", err)
|
||||
}
|
||||
// If the node has the close method, call it.
|
||||
if closer, ok := node.Node.(io.Closer); ok {
|
||||
if err := closer.Close(); err != nil {
|
||||
log.Warn("Can't close node", "id", node.ID(), "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
close(net.quitc)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue