Repository navigation
MINOR: Block instead of spinning while waiting for Flight handshake messages - #1506
Conversation
…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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Good catch. next() now calls sender.onError(e) before it rethrows, so the request stream is errored and the server sees onError and stops waiting on the queue.
Added TestBasicAuth.interruptedClientHandshakeEndsServerStream for it: it waits until the server is parked in ServerAuthWrapper.next, interrupts the client mid-handshake, and checks the server thread leaves next(). Without the onError call it fails with the server still blocked.
…nterrupted An interrupt in next() left doClientAuth without completing or cancelling the outbound stream, so the server could stay blocked waiting for a client message. Signal the error on the request stream before propagating the interruption.
jbonofre
left a comment
There was a problem hiding this comment.
Thanks for the update @Arawoof06! LGTM!
What's Changed
ServerAuthWrappergives the legacyServerAuthHandleran iterator whosenext()spins onLinkedBlockingQueue.poll()until the client sends a handshake message or closes the stream.ServerAuthInterceptorlets Handshake through without a token, so on a server configured with a legacy handler such asBasicServerAuthHandler, 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.ClientAuthWrapperspins the same way on the client while waiting for the server's reply.next()now blocks ontake().onCompleted/onErrorenqueue an end-of-stream marker so a waiting reader wakes up and throws the same exceptions as before, andhasNext()ignores the marker. Valid handshakes are unaffected.Measured against a
FlightServerwithBasicServerAuthHandler, with 4 Handshake streams opened and left idle for 3 s:TestBasicAuth.handshakeBlocksWhileWaitingForClientopens an idle Handshake and checks that the server thread isWAITING. It fails without the fix (expected: <WAITING> but was: <RUNNABLE>). The flight-core tests pass with the fix.