libp2p / libp2p/rust-libp2p

Fix flaky libp2p-kad bootstrap timing test

Open
#6,421 1 comment 0 reactions 0 assignees View on GitHub

@0xsamalt is already working on this.

Since Mar 29, 2026.

  • #6361 by @0xsamalt — open
Dominant language
Rust
Stars
5.6k
Forks
1.3k
Avg merge
8h 47m
Merged PRs (30d)
19

Description

PR #6418 hit a libp2p-kad CI failure in an unrelated change set. The failure looks like a flaky real-time bound in a Kad bootstrap test, and it can block PRs that do not touch Kad.

Failed CI:

The failing test was:

bootstrap::tests::given_periodic_bootstrap_when_routing_table_updated_then_wont_bootstrap_until_next_interval

The job log shows:

thread 'bootstrap::tests::given_periodic_bootstrap_when_routing_table_updated_then_wont_bootstrap_until_next_interval' panicked at protocols/kad/src/bootstrap.rs:275:9:
assertion failed: elapsed < MS_5 * 2

test result: FAILED. 72 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 75.93s

The assertion is checking that a bootstrap scheduled with MS_5 completes in less than MS_5 * 2, so the test depends on a 10 ms wall-clock bound:

const MS_5: Duration = Duration::from_millis(5);

let start = Instant::now();
await_and_do_bootstrap(&mut status).await;
let elapsed = Instant::now().duration_since(start);

assert!(elapsed < MS_5 * 2);

Why this looks unrelated to PR #6418:

  • The PR branch did not change protocols/kad.
  • The changed files were limited to dependency metadata, libp2p-dns, libp2p-mdns, libp2p-tls, the top-level builder DNS wiring, and changelogs.
  • The libp2p-kad dependency tree for normal/dev edges does not go through Hickory, DNS, or mDNS.
  • The exact failing test passed locally once while investigating, and then passed five more times in a loop.

Suggested fix:

Make the test deterministic instead of asserting that a 5 ms timer completes within a 10 ms real-time budget on a shared CI runner. For example, use Tokio's paused time support if it fits this module, or relax/restructure the assertion so scheduler delay does not fail the test when the behavior is otherwise correct.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in protocols/kad/src/bootstrap.rs at bootstrap::tests::given_periodic_bootstrap_when_routing_table_updated_then_wont_bootstrap_until_next_interval and inspect the elapsed-time assertion around MS_5. Run this targeted test, then make its timing check deterministic or independent of scheduler delay. Confirm the test passes reliably on repeated runs.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
networking, testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.