Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
logging: make the swarm less noisy
Browse files Browse the repository at this point in the history
Avoid logging about closed listeners, etc., when shutting down.
  • Loading branch information
Stebalien committed Jun 6, 2019
1 parent 35dc073 commit 9c7976e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ func NewSwarm(ctx context.Context, local peer.ID, peers peerstore.Peerstore, bwc
}

func (s *Swarm) teardown() error {
// Wait for the context to be canceled.
// This allows other parts of the swarm to detect that we're shutting
// down.
<-s.ctx.Done()

// Prevents new connections and/or listeners from being added to the swarm.

s.listeners.Lock()
Expand Down
11 changes: 8 additions & 3 deletions swarm_listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (s *Swarm) AddListenAddr(a ma.Multiaddr) error {
c, err := list.Accept()
if err != nil {
if s.ctx.Err() == nil {
// only log if the swarm is still running.
log.Errorf("swarm listener accept error: %s", err)
}
return
Expand All @@ -88,9 +89,13 @@ func (s *Swarm) AddListenAddr(a ma.Multiaddr) error {
go func() {
defer s.refs.Done()
_, err := s.addConn(c, network.DirInbound)
if err != nil {
// Probably just means that the swarm has been closed.
log.Warningf("add conn failed: ", err)
switch err {
case nil:
case ErrSwarmClosed:
// ignore.
return
default:
log.Warningf("add conn %s failed: ", err)
return
}
}()
Expand Down

0 comments on commit 9c7976e

Please sign in to comment.