Skip to content

fix(bitswap): see peers connected before startup - #1201

Open
lidel wants to merge 1 commit into
mainfrom
fix/bitswap-backfill-existing-conns
Open

fix(bitswap): see peers connected before startup#1201
lidel wants to merge 1 commit into
mainfrom
fix/bitswap-backfill-existing-conns

Conversation

@lidel

@lidel lidel commented Jul 29, 2026

Copy link
Copy Markdown
Member

Note

This mainly aims to remove flakes from CI tests in kubo (found as part of ipfs/kubo#11413)

Problem

Bitswap can wait forever for a block a connected peer already has. Start registers a libp2p notifier, and libp2p only reports connections opened after that, so a peer connected while the node is still coming up is never recorded. Bitswap never sends it a want, and nothing corrects that later: the peer stays invisible for the life of the connection. Routing usually hides this by finding the content elsewhere; without that fallback the fetch just hangs. It surfaced as Kubo's kubo-as-a-library example timing out in CI, where mDNS connects the two nodes while one is still starting.

Fix

  • After registering the notifier, walk the already-open connections and mark those peers connected
  • Skip limited connections, matching what the notifier does
  • Notifier first, so a connection racing this is counted twice at worst, which Connected ignores

This closes the startup window for every embedder, not just Kubo. Nothing changes about how peers are dropped or re-added later. Separate from #1163: that one lost a peer it had already seen, this one never sees it at all.

Start registers a libp2p notifier, which only reports connections opened
from then on, and never looks at the ones already open. A peer connected
while the node was still being built therefore stayed disconnected as
far as Bitswap was concerned, for the whole life of that connection: it
was never sent a want, and nothing later corrected the record. Callers
with routing configured usually found the content another way, so this
surfaced as an occasional hang on nodes that had nothing else to fall
back on.

Take stock of the open connections after registering the notifier, so a
connection opening right at that moment is counted twice at worst, which
the event manager already handles.
@lidel
lidel requested a review from a team as a code owner July 29, 2026 13:11
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.89%. Comparing base (3dcbf9b) to head (36f3a0f).

Files with missing lines Patch % Lines
bitswap/network/bsnet/ipfs_impl.go 50.00% 1 Missing and 1 partial ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1201      +/-   ##
==========================================
+ Coverage   63.87%   63.89%   +0.01%     
==========================================
  Files         269      269              
  Lines       27144    27148       +4     
==========================================
+ Hits        17339    17346       +7     
+ Misses       8095     8090       -5     
- Partials     1710     1712       +2     
Files with missing lines Coverage Δ
bitswap/network/bsnet/ipfs_impl.go 74.64% <50.00%> (-0.36%) ⬇️

... and 12 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant