Files
orca/src/shared/reconnect-jitter.test.ts
T
Jinwoo HongandJinwoo-H 211b2d1a35 fix(runtime): require consecutive missed probes before reaping a paired socket (#12790)
The paired-runtime WS heartbeat terminated a client after a single unanswered
15s ping. One missed pong is UNKNOWN, not proof the peer is gone: a cellular or
Tailscale blackhole, or a stalled TCP retransmit, routinely swallows one pong
from a peer that is still there. Users on flaky paths saw constant drops, each
costing a full redial plus E2EE re-handshake and subscription replay.

Reap now needs MISSED_PROBE_LIMIT (3) consecutive unanswered probes, counted per
socket rather than timed. Any proof of life -- pong or any inbound frame -- clears
the count, as does a resume from a server-loop pause, since a gap the client was
never given a chance to answer must not top up its budget. Missed sweeps still
re-probe, so a recovered path proves itself on the next tick.

Three matches the liveness budgets already in the product: the web client gives
45s (25s idle + 20s probe grace) and the relay control gives 75s. The paired
transport's single miss was the outlier.

Also gives the web client's redial the one-sided jitter the shared-control path
already had, so a fleet dropped by one shared blip does not re-dial in lockstep;
the helper is extracted to src/shared/reconnect-jitter.ts and shared by both.

STA-3320, #12327

Co-authored-by: Jinwoo-H <Jinwoo-H@users.noreply.github.com>
2026-08-05 18:59:20 -07:00

18 lines
620 B
TypeScript

import { describe, expect, it } from 'vitest'
import { withReconnectJitter } from './reconnect-jitter'
describe('withReconnectJitter', () => {
it('never returns less than the backoff floor', () => {
expect(withReconnectJitter(500, () => 0)).toBe(500)
})
it('spreads a fleet that was dropped by one shared blip', () => {
const fleet = Array.from({ length: 32 }, (_, index) =>
withReconnectJitter(500, () => index / 32)
)
expect(new Set(fleet).size).toBeGreaterThan(1)
expect(Math.min(...fleet)).toBeGreaterThanOrEqual(500)
expect(Math.max(...fleet)).toBeLessThanOrEqual(600)
})
})