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:
sukun
2024-08-15 18:18:35 +05:30
committed by GitHub
parent e276a6efad
commit 8a11b7c8e4
4 changed files with 32 additions and 30 deletions
+4
View File
@@ -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()