From 17ba661d1777fc5fe9d9ce5e9a639577b42a7574 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Mon, 20 Feb 2023 22:03:24 +1300 Subject: [PATCH] basichost: don't close the swarm The swarm is not constructed by the basic host, thus is shouldn't be closed by it. --- config/config.go | 9 ++++++++- p2p/host/basic/basic_host.go | 1 - 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index a0805a75eb..167c54b6cb 100644 --- a/config/config.go +++ b/config/config.go @@ -320,7 +320,14 @@ func (cfg *Config) NewNode() (host.Host, error) { fx.Provide(func() event.Bus { return eventbus.NewBus(eventbus.WithMetricsTracer(eventbus.NewMetricsTracer(eventbus.WithRegisterer(cfg.PrometheusRegisterer)))) }), - fx.Provide(func(eventBus event.Bus) (*swarm.Swarm, error) { return cfg.makeSwarm(eventBus, !cfg.DisableMetrics) }), + fx.Provide(func(eventBus event.Bus, lifecycle fx.Lifecycle) (*swarm.Swarm, error) { + sw, err := cfg.makeSwarm(eventBus, !cfg.DisableMetrics) + if err != nil { + return nil, err + } + lifecycle.Append(fx.StopHook(sw.Close)) + return sw, nil + }), fx.Decorate(func(sw *swarm.Swarm, lifecycle fx.Lifecycle) *swarm.Swarm { lifecycle.Append(fx.Hook{ OnStart: func(context.Context) error { diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index 71ad396768..3eaf9f4e35 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -1028,7 +1028,6 @@ func (h *BasicHost) Close() error { _ = h.emitters.evtLocalProtocolsUpdated.Close() _ = h.emitters.evtLocalAddrsUpdated.Close() - h.Network().Close() h.psManager.Close() if h.Peerstore() != nil {