Skip to content

k8s exec test: the fake exec server waits for every SYN_REPLY before writing - #1232

Merged
ZacxDev merged 2 commits into
mainfrom
fix/exec-flood-test-timeout
Dec 4, 2026
Merged

ZacxDev merged 2 commits into
mainfrom
fix/exec-flood-test-timeout

Conversation

@ZacxDev

@ZacxDev ZacxDev commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

TestExecWithOneBufferForStdoutAndStderrIsSafe failed once on main's CI (exec into termy: Timeout occurred, 30.07s). The fault is in the test's fake exec server. The driver is fine.

Root cause

  • apimachinery's SPDY upgrader calls the new-stream handler before it sends that stream's SYN_REPLY. It passes a replySent channel so the server can wait, and the kubelet waits on every one (kubelet/pkg/cri/streaming/remotecommand/httpstream.go, waitStreamReply). The fake ignored it (_ <-chan struct{}).
  • So the stderr stream could reach ServeHTTP with its reply still unsent, and the 64-chunk flood started.
  • On the client, client-go creates error, stdout and stderr streams one at a time and reads none of them until all three exist. spdystream's per-stream dataChan is unbuffered, so the stdout frame worker blocks on the first data frame. Its 50-frame queue fills, and the connection's single read loop then blocks pushing the next frame. It never reaches stderr's SYN_REPLY behind it, and CreateStream times out after createStreamResponseTimeout (30s).

Fix

  • The fake collects every stream's replySent and waits for all of them before writing anything.
  • A new replyLag knob, set in the flood test, holds the stderr reply back by 50ms. The losing interleaving then happens on every run, not about once in a thousand.

Measurements (race-enabled test binary, 8-core host)

condition before after
-count=200 0 / 400 subtests failed 0 / 400
-count=300 -cpu 1,2 1 / 1200 (Timeout occurred, the CI symptom) 0 / 1200 (with the 50ms delay on)
50ms stderr reply delay 2 / 2 (Timeout occurred, 30s each) 0 / 2

Mutation checks:

  • The fix with its wait loop removed: 2 / 2 fail with Timeout occurred.
  • The driver's exec sink removed (the bug this test exists for): the test still fails under -race (DATA RACE plus a short byte count), so what it checks is unchanged.

🤖 Generated with Claude Code

…writing

TestExecWithOneBufferForStdoutAndStderrIsSafe failed once in CI with
"exec into termy: Timeout occurred" after 30s. The fault is in the fake
server, not the driver.

apimachinery's SPDY upgrader calls the new-stream handler BEFORE it sends
that stream's SYN_REPLY, and hands it a replySent channel for exactly this
reason; the kubelet waits on every replySent before it starts the command.
The fake ignored it, so the stderr stream could reach ServeHTTP with its
reply still unsent, and the flood started. On the client, client-go
creates its streams one at a time and reads none until all exist, and
spdystream's per-stream dataChan is unbuffered: the stdout frame worker
blocks on the first data frame, its 50-frame queue fills, and the
connection's single read loop blocks pushing the next one, never reaching
stderr's SYN_REPLY behind it. CreateStream then times out after
createStreamResponseTimeout (30s).

The fake now collects each stream's replySent and waits for all of them
before writing anything. The flood test also sets replyLag, which delays
the stderr reply by 50ms, so the losing interleaving happens on every run
instead of about once in a thousand.

Measured with the race-enabled test binary on an 8-core host:
- before, -count=200: 0 of 400 subtests failed
- before, -count=300 -cpu 1,2: 1 of 1200 failed, "Timeout occurred"
  (the CI symptom)
- before, with the 50ms reply delay: 2 of 2 failed, "Timeout occurred"
  after 30s each
- after (delay on), -count=200: 0 of 400; -count=300 -cpu 1,2: 0 of 1200
- the fix with its wait loop removed (delay on): 2 of 2 failed, Timeout
- the driver's exec sink removed: the test still fails under -race (16
  DATA RACE reports plus a short byte count), so what it checks is unchanged

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ZacxDev
ZacxDev merged commit ce95b0e into main Dec 4, 2026
33 checks passed
@ZacxDev
ZacxDev deleted the fix/exec-flood-test-timeout branch December 4, 2026 14:41
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