Skip to content

Commit 7224e2a

Browse files
authored
Merge pull request #610 from libp2p/fix/bootstrap-block
fix: avoid blocking when bootstrapping
2 parents 68c214e + e1bed2e commit 7224e2a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

dht_bootstrap.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,12 @@ func (dht *IpfsDHT) refreshCpls(ctx context.Context) error {
234234

235235
// Bootstrap tells the DHT to get into a bootstrapped state satisfying the
236236
// IpfsRouter interface.
237-
//
238-
// This just calls `RefreshRoutingTable`.
239237
func (dht *IpfsDHT) Bootstrap(_ context.Context) error {
240-
dht.RefreshRoutingTable()
238+
// Important: don't block!
239+
select {
240+
case dht.triggerRtRefresh <- nil:
241+
default:
242+
}
241243
return nil
242244
}
243245

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

0 commit comments

Comments
 (0)