Przeglądaj źródła

chore(timeout): add a timeout also for advertizing (#564)

Signed-off-by: mudler <[email protected]>
Ettore Di Giacinto 1 rok temu
rodzic
commit
2936cffccf
1 zmienionych plików z 5 dodań i 1 usunięć
  1. 5 1
      pkg/discovery/dht.go

+ 5 - 1
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