Skip to content

Commit

Permalink
Merge pull request ipfs#8166 from ipfs/feat/bootstrap-error
Browse files Browse the repository at this point in the history
feat: print error on bootstrap failure
  • Loading branch information
aschmahmann authored Jun 14, 2021
2 parents 041de2a + 904cc73 commit f05f84a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"runtime"
"sort"
"sync"
"time"

multierror "github.com/hashicorp/go-multierror"

Expand All @@ -22,6 +23,7 @@ import (
oldcmds "github.com/ipfs/go-ipfs/commands"
"github.com/ipfs/go-ipfs/core"
commands "github.com/ipfs/go-ipfs/core/commands"
"github.com/ipfs/go-ipfs/core/coreapi"
corehttp "github.com/ipfs/go-ipfs/core/corehttp"
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
libp2p "github.com/ipfs/go-ipfs/core/node/libp2p"
Expand Down Expand Up @@ -510,6 +512,33 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
fmt.Println("(Hit ctrl-c again to force-shutdown the daemon.)")
}()

// Give the user heads up if daemon running in online mode has no peers after 1 minute
if !offline {
time.AfterFunc(1*time.Minute, func() {
cfg, err := cctx.GetConfig()
if err != nil {
log.Errorf("failed to access config: %s", err)
}
if len(cfg.Bootstrap) == 0 && len(cfg.Peering.Peers) == 0 {
// Skip peer check if Bootstrap and Peering lists are empty
// (means user disabled them on purpose)
log.Warn("skipping bootstrap: empty Bootstrap and Peering lists")
return
}
ipfs, err := coreapi.NewCoreAPI(node)
if err != nil {
log.Errorf("failed to access CoreAPI: %v", err)
}
peers, err := ipfs.Swarm().Peers(cctx.Context())
if err != nil {
log.Errorf("failed to read swarm peers: %v", err)
}
if len(peers) == 0 {
log.Error("failed to bootstrap (no peers found): consider updating Bootstrap or Peering section of your config")
}
})
}

// collect long-running errors and block for shutdown
// TODO(cryptix): our fuse currently doesn't follow this pattern for graceful shutdown
var errs error
Expand Down

0 comments on commit f05f84a

Please sign in to comment.