From b81f577329fce7ebfc0383a3d16d28c4dee46c9e Mon Sep 17 00:00:00 2001 From: vyzo Date: Thu, 14 Feb 2019 19:54:59 +0200 Subject: [PATCH 1/2] add a timeout to Provide in routing.Advertise --- routing.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/routing.go b/routing.go index 6a45de4..0b8369b 100644 --- a/routing.go +++ b/routing.go @@ -26,7 +26,11 @@ 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 or else the DHT may never find any peers + pctx, cancel := context.WithTimeout(ctx, 60*time.Second) + defer cancel() + + err = d.Provide(pctx, cid, true) if err != nil { return 0, err } From 5763f2df55770546922f09b10ffb246e4320130c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Thu, 14 Feb 2019 18:08:24 +0000 Subject: [PATCH 2/2] clarify comment. --- routing.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routing.go b/routing.go index 0b8369b..3f6a973 100644 --- a/routing.go +++ b/routing.go @@ -26,7 +26,9 @@ func (d *RoutingDiscovery) Advertise(ctx context.Context, ns string, opts ...Opt return 0, err } - // this context requires a timeout or else the DHT may never find any peers + // 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()