gcs: fix flaky test on bridge teardown race#2744
Merged
shreyanshjain7174 merged 1 commit intoMay 19, 2026
Merged
Conversation
TestGcsCreateProcess occasionally panicked with Fail in goroutine after Test... completed because the fake guest (simpleGcs) goroutine outlived the test and called t.Error from there. Two layered fixes in guestconnection_test.go: 1. simpleGcsLoop now treats io.ErrUnexpectedEOF as a benign teardown signal alongside io.EOF and io.ErrClosedPipe. The bridge's brdg.Close() closes the underlying io.Pipe synchronously, so simpleGcs can legitimately observe a truncated frame mid-body when the test tears down. Production behavior is unchanged: a real bridge still surfaces ErrUnexpectedEOF as a fatal protocol error. 2. connectGcs now joins the simpleGcs goroutine via t.Cleanup so any future t.Error from background work lands inside the test scope as a normal failure instead of panicking the runtime. Reproduced at ~2/30 iterations pre-fix; 100/100 clean post-fix. Signed-off-by: Shreyansh Jain <shreyanshjain7174@gmail.com>
d2980b4 to
ba7e2da
Compare
rawahars
approved these changes
May 18, 2026
anmaxvl
approved these changes
May 18, 2026
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.
Summary
TestGcsCreateProcessoccasionally panics in CI with:The fake guest goroutine (
simpleGcs) outlives the test and callst.Errorfrom a closed test scope. Observed flake rate locally: ~2/30 iterations; e.g. https://github.com/microsoft/hcsshim/actions/runs/26017233067/job/76470258316.Root cause
bridge.Close()closes the underlyingio.Pipesynchronously without a shutdown handshake. Becauseio.Pipeis unbuffered, a write of one bridge message arrives at the reader in two chunks (16-byte header, then body). IfClose()lands between those chunks,simpleGcs'sReadFull(body)returnsio.EOFafter a partial read, whichreadMessageconverts toio.ErrUnexpectedEOF(bridge.go:277).simpleGcsLooponly whitelistedio.EOF/io.ErrClosedPipe, so the error propagated intot.Errorafter the test had already returned — Go's testing framework then panics.Fix
Two layered changes in
internal/gcs/guestconnection_test.go:simpleGcsLoopalso treatsio.ErrUnexpectedEOFas a benign teardown signal. The fake guest legitimately observes truncated frames when the bridge tears down abruptly; this is purely a test-side accommodation. Production behavior is unchanged — the real bridge still surfacesErrUnexpectedEOFas a fatal protocol error viarecvLoop→kill→ErrBridgeClosed.connectGcsjoins thesimpleGcsgoroutine viat.Cleanup. This ensures any futuret.Errorfrom background work (e.g. the innerio.Copygoroutine in theRPCExecuteProcesscase has the same hazard) lands inside the test scope as a normal failure instead of panicking the runtime.