Repository navigation
k8s exec test: the fake exec server waits for every SYN_REPLY before writing - #1232
Merged
Merged
Conversation
…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
marked this pull request as ready for review
December 4, 2026 13:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TestExecWithOneBufferForStdoutAndStderrIsSafefailed 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
replySentchannel 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{}).ServeHTTPwith its reply still unsent, and the 64-chunk flood started.dataChanis 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, andCreateStreamtimes out aftercreateStreamResponseTimeout(30s).Fix
replySentand waits for all of them before writing anything.replyLagknob, 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)
-count=200-count=300 -cpu 1,2Timeout occurred, the CI symptom)Timeout occurred, 30s each)Mutation checks:
Timeout occurred.-race(DATA RACE plus a short byte count), so what it checks is unchanged.🤖 Generated with Claude Code