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

Commit

Permalink
Merge pull request #12 from libp2p/fix/provide-timeout
Browse files Browse the repository at this point in the history
add a timeout to Provide in routing.Advertise
  • Loading branch information
vyzo authored Feb 14, 2019
2 parents 17aa7d7 + 5763f2d commit 093a432
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ func (d *RoutingDiscovery) Advertise(ctx context.Context, ns string, opts ...Opt
return 0, err
}

err = d.Provide(ctx, cid, true)
// this context requires a timeout; it determines how long the DHT looks for
// closest peers to the key/CID before it goes on to provide the record to them.
// Not setting a timeout here will make the DHT wander forever.
pctx, cancel := context.WithTimeout(ctx, 60*time.Second)
defer cancel()

err = d.Provide(pctx, cid, true)
if err != nil {
return 0, err
}
Expand Down

0 comments on commit 093a432

Please sign in to comment.