image: deflake TestCopyCtx_MidStreamCancel#41
Merged
Conversation
The test's blockingReader returned io.EOF on its second Read after close(br.release). But copyCtx returns nil on EOF (line 26-27) before its next top-of-loop ctx.Err() check, so a scheduling order where the copy goroutine entered the second Read *before* the test called cancel() would observe EOF first and return nil — exactly the intermittent failure seen on main once #39 and #40 landed. Make the reader's second Read block on <-ctx.Done() and return ctx.Err() instead. Now whichever side observes the cancel first yields context.Canceled to copyCtx: either the top-of-loop ctx.Err() check, or the rerr branch propagating the reader's ctx.Err(). Test-only change; production copyCtx is untouched.
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.
What
Fix the intermittent failure of
TestCopyCtx_MidStreamCancelthat surfaced onmainafter #39 and #40 merged in sequence.Why
The test's
blockingReaderreturnedio.EOFon its secondReadonce the test calledclose(br.release). ButcopyCtxreturnsnilon EOF (line 26-27 ofimage/copyctx.go) before its next top-of-loopctx.Err()check. So this scheduling order produced the failure:ctx.Err()(still nil), enters secondsrc.Read.dst.Len() == len(first), callscancel(), thenclose(br.release).(0, io.EOF).copyCtxseesrerr == io.EOF→ returns(written, nil).Result:
error = <nil>, want context.Canceled. Both #39 and #40's PR runs passed in isolation; the failure only showed onmain's run for #40 because of CI scheduling.Fix
Test-only. Give
blockingReadera context, and have its secondReadblock on<-ctx.Done()then returnctx.Err()instead ofio.EOF. Now whichever side observes the cancel first yieldscontext.CanceledtocopyCtx:ctx.Err()returns it directly, or<-ctx.Done()unblocks and returnsctx.Err(), which copyCtx propagates via thererrbranch (line 29-30).Either way,
cerr == context.Canceleddeterministically. No change to productioncopyCtx.Verification
go build ./...andgo vet ./...clean locally (Windows dev-machine constraint precludesgo test).build-and-testjob will verify on Linux.