Skip to content

Flaky 5s timeout in peer.spec.ts ("transfers GPT-sized payload with byte-for-byte reassembly") #1302

In review

Description

@ale18V

Problem

discojs/src/client/decentralized/peer.spec.ts intermittently fails in CI (verify / test / discojs) with Vitest's default 5s timeout on peer > transfers GPT-sized payload with byte-for-byte reassembly:

Error: Test timed out in 5000ms.
 ❯ discojs/src/client/decentralized/peer.spec.ts:82:3

Example failure: https://github.com/epfml/disco/actions/runs/45438603494 (on PR #1290, unrelated to decentralized peer code).

Root causes observed

  1. Loopback UDP packet drops trigger SCTP retransmission stalls under load: Peer.flush() (discojs/src/client/decentralized/peer.ts) bursts up to HIGH_WATER_MARK = 1 MiB (16 × 64 KiB chunks) in a synchronous loop into @roamhq/wrtc, exceeding Linux's default UDP receive buffer (net.core.rmem_default = 212992 bytes, ~208 KiB). Even locally on an idle machine, ~10% of 10 MB transfers spike from ~90 ms to ~705 ms with a ~400 ms inter-chunk gap (usrsctp T3-rtx recovery). On CI runners running 30 Vitest test files in parallel (including gpt.spec.ts, hellaswag.spec.ts, and onnx.spec.ts), passing runs of peer.spec.ts already take ~812–1363 ms, and repeated SCTP retransmissions with backoff push the test past 5,000 ms.
  2. Test timeout is shorter than Peer's own drain timeout: peer.spec.ts uses Vitest's default 5_000 ms timeout, which is half of Peer.drain()'s default MAX_DRAIN_TIME = 10_000 ms (peer.ts:16). For comparison, peer_pool.spec.ts sets { timeout: 10_000 }.
  3. External STUN servers queried on every unit test: Peer (peer.ts:76-85) hardcodes public Google/Twilio STUN servers, causing unnecessary external ICE candidate gathering on every beforeEach.
  4. Silent hangs on peer errors/disconnects: peer.spec.ts does not listen to peer1/peer2 "error" or "close" events, and drain() returns silently if the channel closes, so await receivedPromise hangs until Vitest's timeout instead of failing fast with the actual error.

Proposed fix

  • Set an explicit timeout in discojs/src/client/decentralized/peer.spec.ts (e.g., { timeout: 20_000 }, above MAX_DRAIN_TIME) and attach fail-fast "error" / unexpected "close" handlers in the test setup.
  • Allow configuring iceServers (or an optional RTCConfiguration) on Peer, and pass iceServers: [] in unit tests so loopback tests do not depend on external STUN servers.
  • Evaluate whether HIGH_WATER_MARK / send pacing in Peer.flush() should be tuned for Node/loopback vs. high-RTT WAN throughput (locally, 128 KiB eliminated the 10 MB stalls: 0/20 spikes, max = 112 ms, vs. 1 MiB for WAN BDP).

Activity

  1. added
    type-bug
    scope-discojs
    scope-decentralized
    scope-ci
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope-ciscope-decentralizedscope-discojstype-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions