From e1bed2e4a29f3bdad5713eec443663c3b070b0fd Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Sun, 26 Apr 2020 11:06:19 -0700 Subject: [PATCH] fix: avoid blocking when bootstrapping fixes: https://github.com/ipfs/go-ipfs/issues/7206 --- dht_bootstrap.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dht_bootstrap.go b/dht_bootstrap.go index 5c67aabdf..0b802b8b0 100644 --- a/dht_bootstrap.go +++ b/dht_bootstrap.go @@ -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 } @@ -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 }