api protocol_error ai_generated true

GraphQL 订阅错误:连接初始化超时。未收到 GQL_CONNECTION_INIT 消息。

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

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

其他格式: JSON · Markdown 中文 · English
87%修复率
84%置信度
1证据数
2024-04-22首次发现

版本兼容性

版本状态引入弃用备注
graphql-ws 5.14 active
subscriptions-transport-ws 0.11 active
Apollo Server 4.10 active
HotChocolate 13.0 active

根因分析

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

English

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

官方文档

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

解决方案

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

无效尝试

常见但无效的做法:

  1. 80% 失败

    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% 失败

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