api protocol_error ai_generated true

GraphQL subscription error: Connection initialization timed out. No GQL_CONNECTION_INIT message received.

ID: api/graphql-subscription-connection-init-timeout

Also available as: JSON · Markdown · 中文
87%Fix Rate
84%Confidence
1Evidence
2024-04-22First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
graphql-ws 5.14 active
subscriptions-transport-ws 0.11 active
Apollo Server 4.10 active
HotChocolate 13.0 active

Root Cause

WebSocket connection for GraphQL subscriptions was established but the client did not send the required GQL_CONNECTION_INIT message within the server's timeout window (typically 10-30 seconds).

generic

中文

GraphQL 订阅的 WebSocket 连接已建立,但客户端未在服务器的超时窗口内(通常为 10-30 秒)发送必需的 GQL_CONNECTION_INIT 消息。

Official Documentation

https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md

Workarounds

  1. 95% success Ensure the GraphQL client sends the GQL_CONNECTION_INIT message immediately after the WebSocket connection opens. In Apollo Client, this is automatic, but if using a custom WebSocket, send it in the 'open' event handler.
    Ensure the GraphQL client sends the GQL_CONNECTION_INIT message immediately after the WebSocket connection opens. In Apollo Client, this is automatic, but if using a custom WebSocket, send it in the 'open' event handler.
  2. 90% success Use a library that handles the handshake automatically, such as graphql-ws client or Apollo Client's subscription support, instead of raw WebSocket.
    Use a library that handles the handshake automatically, such as graphql-ws client or Apollo Client's subscription support, instead of raw WebSocket.

中文步骤

  1. 确保 GraphQL 客户端在 WebSocket 连接打开后立即发送 GQL_CONNECTION_INIT 消息。在 Apollo Client 中这是自动的,但如果使用自定义 WebSocket,请在 'open' 事件处理程序中发送。
  2. 使用自动处理握手的库,例如 graphql-ws 客户端或 Apollo Client 的订阅支持,而不是原始 WebSocket。

Dead Ends

Common approaches that don't work:

  1. 80% fail

    A longer timeout masks the real issue (missing init message) and may cause resource leaks from stale connections; the client should send init promptly.

  2. 90% fail

    Reconnection does not fix the missing init message; the same error will recur unless the client code is fixed to send GQL_CONNECTION_INIT.