Skip to content

Commit

Permalink
Remove repeated close host call (#2147)
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann authored Sep 19, 2024
1 parent f3c885f commit 4fb5d0f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ func (s *Service) SubscribePeerConnectednessChanged(ctx context.Context) (<-chan

// Run starts the p2p service. Calling any other function before run is undefined behaviour
func (s *Service) Run(ctx context.Context) error {
defer s.host.Close()
defer func() {
if err := s.host.Close(); err != nil {
s.log.Warnw("Failed to close host", "err", err)
}
}()

err := s.dht.Bootstrap(ctx)
if err != nil {
Expand Down Expand Up @@ -268,7 +272,7 @@ func (s *Service) Run(ctx context.Context) error {
if err := s.dht.Close(); err != nil {
s.log.Warnw("Failed stopping DHT", "err", err.Error())
}
return s.host.Close()
return nil
}

func (s *Service) setProtocolHandlers() {
Expand Down

0 comments on commit 4fb5d0f

Please sign in to comment.