Skip to content

Commit

Permalink
Merge pull request #610 from libp2p/fix/bootstrap-block
Browse files Browse the repository at this point in the history
fix: avoid blocking when bootstrapping
  • Loading branch information
Stebalien authored Apr 26, 2020
2 parents 68c214e + e1bed2e commit 7224e2a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions dht_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,12 @@ func (dht *IpfsDHT) refreshCpls(ctx context.Context) error {

// Bootstrap tells the DHT to get into a bootstrapped state satisfying the
// IpfsRouter interface.
//
// This just calls `RefreshRoutingTable`.
func (dht *IpfsDHT) Bootstrap(_ context.Context) error {
dht.RefreshRoutingTable()
// Important: don't block!
select {
case dht.triggerRtRefresh <- nil:
default:
}
return nil
}

Expand All @@ -248,9 +250,12 @@ func (dht *IpfsDHT) Bootstrap(_ context.Context) error {
func (dht *IpfsDHT) RefreshRoutingTable() <-chan error {
res := make(chan error, 1)
select {
// FIXME: this can block. Ideally, we'd return a channel without blocking.
// https://github.com/libp2p/go-libp2p-kad-dht/issues/609
case dht.triggerRtRefresh <- res:
case <-dht.ctx.Done():
res <- dht.ctx.Err()
close(res)
}
return res
}

0 comments on commit 7224e2a

Please sign in to comment.