Skip to content

Commit

Permalink
basichost: don't close the swarm
Browse files Browse the repository at this point in the history
The swarm is not constructed by the basic host, thus is shouldn't be
closed by it.
  • Loading branch information
marten-seemann committed Sep 3, 2023
1 parent 34b3797 commit 17ba661
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 8 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 17ba661

Please sign in to comment.