fix(client): wait for output pump before exit to prevent truncated stdout#1009
Open
He-Pin wants to merge 1 commit into
Open
fix(client): wait for output pump before exit to prevent truncated stdout#1009He-Pin wants to merge 1 commit into
He-Pin wants to merge 1 commit into
Conversation
…dout Motivation: E2ETests.secondInvocationReusesServer was flaky because the output pumper thread (outThread) is a daemon thread. After serverLock.await() returns, the main thread immediately reads the exit code and calls System.exit(), killing the daemon thread before it finishes draining the socket buffer to stdout. This results in empty or truncated output. Modification: Add outThread.join(5_000) after serverLock.await() in SjsonnetClientMain.java. The server closes its end of the socket before releasing serverLock, so by the time await() returns, the socket has EOF waiting. The join gives the output pumper thread time to read all remaining data and terminate naturally before the client process exits. Result: E2E tests pass consistently across 5+ consecutive runs (previously flaky).
5298215 to
84ed5e5
Compare
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.
Motivation
E2ETests.secondInvocationReusesServerwas flaky because the outputpumper thread (
outThread) is a daemon thread. AfterserverLock.await()returns, the main thread immediately reads theexit code and calls
System.exit(), killing the daemon thread beforeit finishes draining the socket buffer to stdout. This results in
empty or truncated output.
Modification
Add
outThread.join(5_000)afterserverLock.await()inSjsonnetClientMain.java. The server closes its end of the socketbefore releasing
serverLock, so by the timeawait()returns thesocket has EOF waiting. The join gives the output pumper thread time
to read all remaining data and terminate naturally before the client
process exits.
Result
E2E tests pass consistently across 5+ consecutive runs (previously
flaky). No deadlock or hang risk —
ProxyStreamPumperreads untilEOF from the closed socket, then exits cleanly. The 5-second timeout
is generous relative to typical socket drain latency (<100ms).
References