From 2936cffccf01aa71525ff9daa6a102e8ba361eb2 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Tue, 27 Aug 2024 13:02:17 +0200 Subject: [PATCH] chore(timeout): add a timeout also for advertizing (#564) Signed-off-by: mudler --- pkg/discovery/dht.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/discovery/dht.go b/pkg/discovery/dht.go index 7226cb46..794b4a88 100644 --- a/pkg/discovery/dht.go +++ b/pkg/discovery/dht.go @@ -224,12 +224,16 @@ func (d *DHT) FindClosePeers(ll log.StandardLogger, onlyStaticRelays bool, stati func (d *DHT) announceAndConnect(l log.StandardLogger, ctx context.Context, kademliaDHT *dht.IpfsDHT, host host.Host, rv string) error { l.Debug("Announcing ourselves...") + + tCtx, c := context.WithTimeout(ctx, time.Second*120) + defer c() routingDiscovery := discovery.NewRoutingDiscovery(kademliaDHT) - routingDiscovery.Advertise(ctx, rv) + routingDiscovery.Advertise(tCtx, rv) l.Debug("Successfully announced!") // Now, look for others who have announced // This is like your friend telling you the location to meet you. l.Debug("Searching for other peers...") + peerChan, err := routingDiscovery.FindPeers(ctx, rv) if err != nil { return err