mirror of
https://github.com/libp2p/go-libp2p.git
synced 2026-04-23 00:27:05 +08:00
basic_host: close swarm on Close (#2916)
Using the `BasicHost` constructor transfers the ownership of the swarm. This is similar to how using `libp2p.New` transfers the ownership of user provided config options like `ResourceManager`, all of which are closed on `host.Close`
This commit is contained in:
@@ -1080,6 +1080,10 @@ func (h *BasicHost) Close() error {
|
||||
_ = h.emitters.evtLocalProtocolsUpdated.Close()
|
||||
_ = h.emitters.evtLocalAddrsUpdated.Close()
|
||||
|
||||
if err := h.network.Close(); err != nil {
|
||||
log.Errorf("swarm close failed: %v", err)
|
||||
}
|
||||
|
||||
h.psManager.Close()
|
||||
if h.Peerstore() != nil {
|
||||
h.Peerstore().Close()
|
||||
|
||||
Reference in New Issue
Block a user