Repository navigation
fix(runner): stop reusing the stderr read buffer across chunks - #294
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
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
OutputCaptureRunner.CaptureOutputreads stderr into a single 1024-byte buffer that is allocated once, outside the read loop, and sendsbuf[:n]on the unbuffered stderr channel. Once the receiver takes the slice, the reader goroutine immediately callsReadagain into the same backing array. The receiver can then see the bytes of the next chunk in place of the chunk it received, so stderr returned by/v1/sandbox/runcan be corrupted or duplicated. The stdout goroutine already allocates a new buffer per read and does not have this problem.This change moves the stderr buffer allocation inside the loop, matching the stdout reader.
Changes
internal/core/runner/output_capture.go: allocate the stderr read buffer per iteration.internal/core/runner/output_capture_test.go: addTestCaptureOutputDoesNotReuseStderrChunkBuffer, which receives the first stderr chunk, lets the reader consume a second chunk, and checks that the first chunk is unchanged.Testing
The
runnerpackageinitcreates the sandbox user, so the unit tests run as root (the CI workflow runs onlytests/integration_tests).expected first stderr chunk to stay intact, got "XXXXX".go test ./internal/core/runner/ -count=1: all 4 tests pass.gofmtandgo vetare clean.Fixes #293