From 831b83e1c4b6ce243f01247d67e62c1adb9ba989 Mon Sep 17 00:00:00 2001 From: Daniel Norman <1992255+2color@users.noreply.github.com> Date: Tue, 6 Aug 2024 21:19:57 +0200 Subject: [PATCH] fix(bitswap): increase timeout to ensure hole punching completes (#651) Co-authored-by: Marcin Rataj --- CHANGELOG.md | 1 + bitswap/network/ipfs_impl.go | 7 +------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5475412c2..17e71b53b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ The following emojis are used to highlight certain changes: - `boxo/gateway` now correctly returns 404 Status Not Found instead of 500 when the requested content cannot be found due to offline exchange, gateway running in no-fetch (non-recursive) mode, or a similar restriction that only serves a specific set of CIDs. - `bitswap/client` fix memory leak in BlockPresenceManager due to unlimited map growth. +- `bitswap/network` fixed race condition when a timeout occurred before hole punching completed while establishing a first-time stream to a peer behind a NAT ### Security diff --git a/bitswap/network/ipfs_impl.go b/bitswap/network/ipfs_impl.go index ac9ab66a6..7acc3abcc 100644 --- a/bitswap/network/ipfs_impl.go +++ b/bitswap/network/ipfs_impl.go @@ -28,8 +28,6 @@ import ( var log = logging.Logger("bitswap/network") -var connectTimeout = time.Second * 5 - var ( maxSendTimeout = 2 * time.Minute minSendTimeout = 10 * time.Second @@ -323,10 +321,7 @@ func (bsnet *impl) SendMessage( p peer.ID, outgoing bsmsg.BitSwapMessage, ) error { - tctx, cancel := context.WithTimeout(ctx, connectTimeout) - defer cancel() - - s, err := bsnet.newStreamToPeer(tctx, p) + s, err := bsnet.newStreamToPeer(ctx, p) if err != nil { return err }