Skip to content

Commit 1570c5a

Browse files
committed
fix(tls): exit handshake loop on NOT_HANDSHAKING to kill latent busy-spin
The NEED_TASK branch reads sslEngine.getHandshakeStatus(), which per the JSSE contract never returns FINISHED -- it returns NOT_HANDSHAKING once the handshake completes. If a delegated task were the terminal handshake step, the loop would land on NOT_HANDSHAKING, match no switch case, and busy-spin at 100% CPU with no deadline escape. Exit the loop on NOT_HANDSHAKING (a completed handshake) as well as FINISHED, closing this latent/provider-dependent spin path.
1 parent e3e854d commit 1570c5a

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

core/src/main/java/io/questdb/client/network/JavaTlsClientSocket.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,12 @@ private int readFromSocket() {
514514
*/
515515
private void runHandshake(SocketReadinessWaiter waiter) throws SSLException, TlsSessionInitFailedException {
516516
SSLEngineResult.HandshakeStatus handshakeStatus = sslEngine.getHandshakeStatus();
517-
while (handshakeStatus != SSLEngineResult.HandshakeStatus.FINISHED) {
517+
// Exit on NOT_HANDSHAKING as well as FINISHED: getHandshakeStatus() (used by the NEED_TASK
518+
// branch) never returns FINISHED per the JSSE contract -- it returns NOT_HANDSHAKING once the
519+
// handshake completes. Without this, a delegated task that is the terminal step would leave the
520+
// loop on NOT_HANDSHAKING, match no case, and busy-spin forever with no deadline escape.
521+
while (handshakeStatus != SSLEngineResult.HandshakeStatus.FINISHED
522+
&& handshakeStatus != SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) {
518523
switch (handshakeStatus) {
519524
case NEED_TASK:
520525
Runnable task;

0 commit comments

Comments
 (0)