You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] WebSocket heartbeat defaults (2s interval + 2 missed) tear down connections on mobile / high-latency networks → ~12s reconnect loop
#9797
dsh-api-gateway's WebSocket heartbeat defaults are too aggressive for mobile and high-latency networks. The server terminates a healthy connection after roughly 4–6 seconds of PONG delay — which mobile networks routinely exceed — producing a permanent reconnect loop (~12s cycle) for remote/domain-access users.
Network: China Mobile 5G (high latency + intermittent packet loss)
Browser: macOS Safari / Chrome
Root cause
In packages/dsh-api-gateway/lib/index.js (compiled 0.2.0-rc.2):
constDEFAULT_WEBSOCKET_HEARTBEAT_INTERVAL_MS=2e3;// line 551 — 2 secondsconstMAX_MISSED_HEARTBEATS=2;// line 172 — hard-coded
RemoteStreamMuxServer.startHeartbeat() pings every websocketHeartbeatIntervalMs (default 2s) and calls socket.terminate() once MAX_MISSED_HEARTBEATS (2) consecutive PONGs are missed (line 244). A single PONG round-trip delay of >~4s — routine on mobile — therefore tears down an otherwise-healthy connection.
Observed behavior
nginx error log, repeating every ~10–14s:
recv() failed (104: Connection reset by peer) while proxying upgraded connection … /api/remote.mux
nginx access log shows /api/remote.mux reconnecting every ~10–14s in bursts.
The DSH server journal is silent — the heartbeat termination is not logged, which made this very hard to diagnose (the disconnect looks like a client-side RST, not a server decision).
Suggested fix
Raise DEFAULT_WEBSOCKET_HEARTBEAT_INTERVAL_MS from 2e3 to 30000 (industry-standard keepalive is 20–60s).
Make MAX_MISSED_HEARTBEATS configurable instead of a hard-coded constant.
Log a warning before socket.terminate() (missed count + interval) so this class of issue is diagnosable.
Verified workaround
Setting websocketHeartbeatIntervalMs: 60000 on the typert-gateway (@deepseek-ai/dsh-api-gateway) config eliminates the reconnect loop:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
TL;DR
dsh-api-gateway心跳默认 2s 一次、连丢 2 个 pong 就socket.terminate()MAX_MISSED_HEARTBEATS改为可配置;terminate 前加日志websocketHeartbeatIntervalMs: 60000Summary
dsh-api-gateway's WebSocket heartbeat defaults are too aggressive for mobile and high-latency networks. The server terminates a healthy connection after roughly 4–6 seconds of PONG delay — which mobile networks routinely exceed — producing a permanent reconnect loop (~12s cycle) for remote/domain-access users.Environment
0.2.0-rc.2https://…→ nginx →127.0.0.1:3080)Root cause
In
packages/dsh-api-gateway/lib/index.js(compiled0.2.0-rc.2):RemoteStreamMuxServer.startHeartbeat()pings everywebsocketHeartbeatIntervalMs(default 2s) and callssocket.terminate()onceMAX_MISSED_HEARTBEATS(2) consecutive PONGs are missed (line 244). A single PONG round-trip delay of >~4s — routine on mobile — therefore tears down an otherwise-healthy connection.Observed behavior
recv() failed (104: Connection reset by peer) while proxying upgraded connection … /api/remote.muxsend() failed (32: Broken pipe) while proxying upgraded connection … /api/remote.mux/api/remote.muxreconnecting every ~10–14s in bursts.Suggested fix
DEFAULT_WEBSOCKET_HEARTBEAT_INTERVAL_MSfrom2e3to30000(industry-standard keepalive is 20–60s).MAX_MISSED_HEARTBEATSconfigurable instead of a hard-coded constant.socket.terminate()(missed count + interval) so this class of issue is diagnosable.Verified workaround
Setting
websocketHeartbeatIntervalMs: 60000on thetypert-gateway(@deepseek-ai/dsh-api-gateway) config eliminates the reconnect loop:Related
中文一句话简述:
「
dsh-api-gateway的 WebSocket 心跳默认值过于激进:默认 2 秒 ping 一次、连丢 2 个 pong 就socket.terminate()。移动/高延迟网络下 pong 单程超过约 4 秒即触发误杀,导致 ~12 秒一次的重连循环;且断开时无日志、难以排查。建议:默认间隔改 30s、MAX_MISSED_HEARTBEATS改为可配置、terminate 前加日志。」All reactions