Skip to content

Flaky CI tests investigation #1830

Closed

Description

@thiras

Summary

Investigation of flaky CI tests in the deCDN project. The CI infrastructure is well-structured with proper allowed-skips, but several test suites have inherent flakiness issues.

Flakiness Issues

1. Probe rate limiter tests (crates/node/tests/probe_loopback.rs)

  • probe_rate_limit_returns_rate_limited_close_code (line 864): Two-connection form flaked under cargo nextest run because the second connection's establishment raced the first's teardown on the shared client endpoint. The accept loop assumed it would receive exactly two Incomings. Code comment lines 860-862 explicitly documents this.
  • probe_three_layer_limiter_rejects_per_peer (line 967): Same connection retry racing issue with per-peer bucket draining.

2. Known QUIC driver wedge (crates/node/tests/support/mod.rs:197-237)

3. DHT integration tests (crates/node/tests/dht_integration.rs)

  • Race conditions in routing table convergence
  • Negative cache TTL expiry under live clock (anchored on Instant, cannot be driven by tokio::time pause/advance)
  • Bucket eviction under node departure

4. Test scheduling non-determinism

  • cargo nextest run schedules tests differently across runs
  • Multi-threaded tests have contention issues

5. E2E concurrency

  • --test-threads 2 used specifically because "more at once oversubscribes the 4-core runner and turns poll-based assertions flaky" (ci.yml:824-826)

6. Timeout sensitivity

  • Fixed-duration tokio::time::timeout() calls affected by CI runner load
  • Several tests use start_paused = true + tokio::time::advance() to fast-forward past deadlines (e.g., probe_read_timeout_resets_stream_with_zero_code at line 731)

7. Shutdown/teardown pattern

  • The shutdown function covers the whole call rather than one stage/endpoint, so a single wedge costs the full 10s timeout

Recommendations

  • Fix the two-connection race in probe rate limiter tests by restructuring to avoid racing connections on a shared endpoint
  • Address the QUIC driver wedge (Pull legs run on ephemeral per-serve runtimes, stranding shared connection drivers (HTTP + QUIC) #1675) in the shutdown function — currently only warns, should fail or have better handling
  • Reduce DHT test parallelism or add more deterministic seeding
  • Maintain --test-threads 2 for E2E journeys (already configured)
  • Keep start_paused = true pattern for tests needing to fast-forward past timeouts (already used in probe tests)
  • Monitor the #1675 QUIC driver issue

CI Status

The test job runs cargo llvm-cov nextest --workspace --lcov and completed successfully. The ci-success gate has allowed-skips for known-flaky tests (fmt, clippy, test, doctest, deny, doc, public-api, adr-book-list, pr-title, markdownlint, anvil-e2e-settlement, anvil-e2e-journeys, solidity-fmt, solidity-build-test, solidity-coverage, solidity-solhint, solidity-slither, solidity-aderyn, ed25519-vectors, docker-build, packaging).

Activity

  1. yigitdot commented on Aug 26, 2026

    @yigitdot
    Contributor

    Triage against main (969c7d5)

    Verified each of the seven claims. Four are stale — they describe defects that later PRs closed, and the issue read historical rationale left in code comments as live defects. Three survive, all in crates/node/tests/dht_integration.rs plus one constant collision in the shared teardown helper.

    # Claim Verdict
    1 Probe rate-limiter tests race two connections on a shared client endpoint; accept loop assumes exactly two Incomings Stale. Closed by #691 (out-of-band bucket pre-drain) and #1594/#1595 (bounded-retry observer). Both tests now pre-drain the bucket through a test hook, bind a fresh client endpoint per attempt, and run an unbounded swallow-everything accept loop with no count assumption. The two-connection shape survived only as prose in the doc comment this issue quotes.
    2 shutdown's fixed ABANDON_DRAIN sleep; warns rather than fails Mostly stale. #1779 replaced the sleep with a bounded ConnDrain::wait_drained plus decdn_node_pull_abandon_drain_timeout_total. Warn-not-fail is deliberate and documented. One real defect behind it — row 7.
    3 DHT tests: routing convergence races, negative-cache TTL, bucket eviction Partly real. Bucket eviction is pure and synchronous; routing-table mutation in the convergence tests is in-process and synchronous. The 3s round_timeout and the 750ms negative-cache TTL are both latency assertions on a coverage-instrumented runner. Fixed.
    4 nextest schedules tests differently across runs Not actionable — that is nextest working as designed. The fix is per-test determinism.
    5 E2E --test-threads 2 Already configured (.github/workflows/ci.yml:782-783).
    6 Fixed-duration tokio::time::timeout sensitivity Partly real. One instance is a coin flip against the implementation's own bound. Fixed.
    7 shutdown covers the whole call, so one wedge costs the full 10s The shape is by design (support/mod.rs:161-166); the value was the defect. Fixed.

    Measured, so the claims are not taken on faith

    Three runs of cargo nextest run -p decdn-node --test dht_integration — plain, under 12 spinning background loops, and under cargo llvm-cov nextest — on a 14-core darwin box:

    Test plain +CPU load +llvm-cov Budget
    bucket_overflow_… 0.009s 0.016s 0.018s none (pure)
    …converges_after_peer_departs 0.276s 0.314s 0.393s 3s round
    …converges_via_closer_nodes_second_round 0.312s 0.317s 0.379s 3s round, ×2
    …negative_cache_expires_after_ttl 1.395s 1.411s 1.461s 750ms TTL
    …tolerates_unreachable_peer 6.315s 6.337s 6.425s 12s guard

    Being precise about what this does and does not show:

    • tolerates_unreachable_peer is demonstrably mis-sized. It burns 6.3–6.4s against a 12s guard, and 12s is exactly MAX_LOOKUP_ROUNDS (4) × round_timeout (3s) — the implementation's own worst case, so the guard sits on the ceiling rather than clearing it. The figure is load-independent across all three runs, so it is fixed timeout cost: the lookup burns two rounds, while its comment claimed "at most one round_timeout (3s)".
    • The negative-cache TTL race is latent, not reproduced. Coverage amplification on this box is only ~1.2–1.4×, leaving roughly a 5× margin on the quantity actually at risk. I could not make it fail locally and will not claim otherwise. It is still worth fixing: CI is a 4-core runner executing the whole workspace under llvm-cov, a far harsher amplifier, and Flaky serve-miss coalescing tests under CI coverage contention (early-eof / peer hang, B3 #1656) #1673 was attributed to exactly that starvation.

    What landed

    • Negative-cache expiry — suppression now runs under the production TTL, which nothing in the test can outlive, and expiry is forced on the one key under test by re-recording it with a Duration::ZERO TTL (entries hold an absolute expiry; contains_active reads expiry <= now as elapsed). The 1100ms sleep goes with it: 1.40s → 0.35s. Wall-clock TTL passage stays covered by the negative_cache unit tests and node_origin_pull's refusal suite.
    • round_timeout split — a convergence budget sitting just above DHT_CLIENT_TIMEOUT (so the per-RPC cap stays the binding constraint), and the short budget named only where a timeout is the point. The hang guard now clears the lookup's ceiling instead of matching it.
    • Bounded teardown — the file routed teardown through support::shutdown instead of one unbounded close().await and a fire-and-forget spawn. A handler panic in the accept loop now fails its test rather than being discarded by the abort.
    • SHUTDOWN_TIMEOUT (10s) equalled ABANDON_DRAIN_CAP (10s) — one ceilinged abandon drain could consume the whole teardown budget before the first close was attempted, reporting 0/M endpoints closed for a run in which nothing was wedged. A false stranded-driver reading on the one channel that keeps Pull legs run on ephemeral per-serve runtimes, stranding shared connection drivers (HTTP + QUIC) #1675 visible. Raised to clear the drain cap.
    • Comment canon — the changelog-voice paragraphs describing the removed two-connection probe design are rewritten in present tense. They are what made this issue file a fixed race as live.

    Deliberately not done

    Verification: cargo clippy --workspace --all-targets -- -D warnings clean, cargo fmt --check clean, cargo doc -p decdn-node clean, full decdn-node package 1038/1038 passing with no SLOW and no teardown exceeded lines, and dht_integration green 20/20 in a repeat loop.

  2. moved this from Backlog to In progress in deCDNon Aug 26, 2026
  3. added
    kind:bug
    kind:test
    prio:medium
    on Aug 26, 2026
  4. moved this from In progress to Done in deCDNon Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:bugkind:testprio:medium

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions