Skip to content

MINOR: Block instead of spinning while waiting for Flight handshake messages - #1506

Open
Arawoof06 wants to merge 1 commit into
apache:mainfrom
Arawoof06:handshake-busy-wait
Open

Arawoof06 wants to merge 1 commit into
apache:mainfrom
Arawoof06:handshake-busy-wait

Conversation

@Arawoof06

Copy link
Copy Markdown
Contributor

What's Changed

ServerAuthWrapper gives the legacy ServerAuthHandler an iterator whose next() spins on LinkedBlockingQueue.poll() until the client sends a handshake message or closes the stream. ServerAuthInterceptor lets Handshake through without a token, so on a server configured with a legacy handler such as BasicServerAuthHandler, an unauthenticated client can open Handshake streams, send nothing, and keep one executor thread per stream at full CPU for as long as the stream stays open. ClientAuthWrapper spins the same way on the client while waiting for the server's reply.

next() now blocks on take(). onCompleted/onError enqueue an end-of-stream marker so a waiting reader wakes up and throws the same exceptions as before, and hasNext() ignores the marker. Valid handshakes are unaffected.

Measured against a FlightServer with BasicServerAuthHandler, with 4 Handshake streams opened and left idle for 3 s:

before: wall=3.04s, server executor CPU=8.09s
after:  wall=3.03s, server executor CPU=0.01s

TestBasicAuth.handshakeBlocksWhileWaitingForClient opens an idle Handshake and checks that the server thread is WAITING. It fails without the fix (expected: <WAITING> but was: <RUNNABLE>). The flight-core tests pass with the fix.

…essages

The legacy handshake iterators busy-waited on the message queue, so an
idle Handshake stream kept a server executor thread at full CPU before
authentication. Block on the queue and wake the reader with an
end-of-stream marker instead.
final byte[] bytes;
try {
bytes = messages.take();
} catch (InterruptedException e) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When take() is interrupted, this exception exits doClientAuth before the outbound handshake stream is completed or cancelled. The server can remain blocked waiting for a client message.
I would signal an error on the request stream before propagating the interruption.

@jbonofre jbonofre added the bug-fix PRs that fix a big. label Nov 19, 2026
@apache apache deleted a comment from github-actions Bot Nov 19, 2026
@github-actions github-actions Bot added this to the 20.0.0 milestone Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PRs that fix a big.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants