Skip to content

fix: skip pre-ack messages during WebSocketGraphQLClient handshake - #2343

Merged
jjacobs44 merged 2 commits into
Netflix:masterfrom
goingforstudying-ctrl:fix/websocket-handshake-pre-ack-messages
Sep 8, 2026
Merged

jjacobs44 merged 2 commits into
Netflix:masterfrom
goingforstudying-ctrl:fix/websocket-handshake-pre-ack-messages

Conversation

@goingforstudying-ctrl

Copy link
Copy Markdown
Contributor

Fixes #1328

What

Per the subscriptions-transport-ws protocol the server answers connection_init with connection_ack, but some servers emit other messages first. Hasura, for example, sends a ka (keep-alive) immediately after connecting (hasura/graphql-engine#7002). WebSocketGraphQLClient.doHandshake() takes the first message off the wire and throws if it isn't the ack, so any subscription against such a server fails during the handshake:

graphql.GraphQLException: Acknowledgement expected from server, received OperationMessage(type=ka, payload=null, id=)

Fix

The handshake now keeps waiting for the ack and skips anything else that arrives first, logging skipped messages at debug level, still bounded by the same acknowledgement timeout.

One case is not skipped: connection_error. It means the server rejected the connection_init, so the handshake now fails right away with the server's payload instead of sitting behind the timeout.

Added requires org.slf4j to the module descriptor for the new debug logging (slf4j-api was already on the compile classpath).

Tests

Updated WebSocketGraphQLClientTest:

The previous errorsIfMessageOtherThanAckFromServer test asserted the strict behavior the issue asks to change, so it is replaced by the tests above. timesOutIfNoAckFromServer is unchanged and still passes: with no ack at all, the handshake times out as before.

Both new skip tests fail against the current implementation, and the full :graphql-dgs-client:test suite passes with the fix.

Some servers (Hasura being a known example) emit keep-alive messages
before the connection ack. The handshake took the first received message
and threw if it was not the ack, aborting the connection. Skip anything
that is not the ack and keep waiting for it, still bounded by the
acknowledgement timeout. A connection error is not skipped: it fails the
handshake right away with the server's payload.
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.

bug: WebSocketGraphQLClient handshake fails if it receives a keep alive message before connection ack

2 participants