Skip to content

Handle slow TCP client handshake#1546

Merged
jfallows merged 1 commit intoaklivity:developfrom
jfallows:tcp-connect-slow-handshake
Aug 28, 2025
Merged

Handle slow TCP client handshake#1546
jfallows merged 1 commit intoaklivity:developfrom
jfallows:tcp-connect-slow-handshake

Conversation

@jfallows
Copy link
Contributor

Description

Selector and OP_CONNECT

  • In Selector, OP_CONNECT means “the socket is ready to finish the connection”, not necessarily that the handshake is complete.
  • This readiness is based on low-level OS signals:
  • On Linux/BSD/macOS: the kernel sets socket writable once the handshake progresses enough for connect() to be completed or fails immediately.
  • The selector interprets a writable socket in non-blocking connect as OP_CONNECT ready.
  • Key point: ready-to-finish does not guarantee finishConnect() will succeed immediately.

Why finishConnect() can still return false

Even after the OS signals writable / OP_CONNECT ready:

  • The TCP handshake may still be in progress (delays, packet loss, retransmission).
  • The channel must call finishConnect() to:
    • Complete the handshake in Java’s SocketChannel API.
    • Update the internal channel state.
    • Assign local/remote addresses.
  • If handshake is still incomplete, finishConnect() returns false — the Java API is just reporting the true channel state.

@jfallows jfallows requested a review from akrambek August 28, 2025 01:26
@jfallows jfallows merged commit 422c5d6 into aklivity:develop Aug 28, 2025
39 checks passed
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.

2 participants