Skip to content

Fix race conditions in TlsHandshakeTimeoutServer#824

Merged
rschmitt merged 1 commit intoapache:masterfrom
rschmitt:timeout-race
Apr 23, 2026
Merged

Fix race conditions in TlsHandshakeTimeoutServer#824
rschmitt merged 1 commit intoapache:masterfrom
rschmitt:timeout-race

Conversation

@rschmitt
Copy link
Copy Markdown
Contributor

close() did not wait for the server thread to finish, so it could read stale state (requestReceived, throwable) while the thread was still running. This caused two intermittent failures:

  • "Never received a request": close() checked requestReceived before the server thread set it after accept() returned.
  • "Exception thrown while TlsHandshakeTimerOuter was running": the server thread got an expected IOException or BUFFER_UNDERFLOW when the client timed out and disconnected, and close() rethrew it.

Fix: store the Thread reference and join() it in close() after closing the sockets. Remove the requestReceived and throwable checks since all server-side exceptions are expected (the client is designed to time out) and client-side assertions already validate correctness.

`close()` did not wait for the server thread to finish, so it could read
stale state (`requestReceived`, `throwable`) while the thread was still
running. This caused two intermittent failures:

- "Never received a request": `close()` checked requestReceived before
  the server thread set it after accept() returned.
- "Exception thrown while TlsHandshakeTimerOuter was running": the
  server thread got an expected IOException or BUFFER_UNDERFLOW when the
  client timed out and disconnected, and `close()` rethrew it.

Fix: store the Thread reference and `join()` it in `close()` after
closing the sockets. Remove the `requestReceived` and `throwable` checks
since all server-side exceptions are expected (the client is designed to
time out) and client-side assertions already validate correctness.
@rschmitt rschmitt merged commit 4b26224 into apache:master Apr 23, 2026
10 checks passed
@rschmitt rschmitt deleted the timeout-race branch April 23, 2026 00:23
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