Skip to content

fix(client): wait for output pump before exit to prevent truncated stdout#1009

Open
He-Pin wants to merge 1 commit into
databricks:masterfrom
He-Pin:fix-flaky-e2e-secondinvocation
Open

fix(client): wait for output pump before exit to prevent truncated stdout#1009
He-Pin wants to merge 1 commit into
databricks:masterfrom
He-Pin:fix-flaky-e2e-secondinvocation

Conversation

@He-Pin

@He-Pin He-Pin commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

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). No deadlock or hang risk — ProxyStreamPumper reads until
EOF from the closed socket, then exits cleanly. The 5-second timeout
is generous relative to typical socket drain latency (<100ms).

References

…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).
@He-Pin He-Pin force-pushed the fix-flaky-e2e-secondinvocation branch from 5298215 to 84ed5e5 Compare June 20, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant