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

add a timeout to Provide in routing.Advertise #12

Merged
merged 2 commits into from
Feb 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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