fix(drive): detect half-open realtime sockets with keepalive pings#81
Merged
Conversation
A NAT/edge-dropped WebSocket looks identical to a quiet library: the watch client waited forever on a dead socket and missed every remote change (an MCP edit only synced after a manual pause/resume). Ping the server every 30s and tear the socket down when nothing comes back within 10s, letting the existing reconnect + server replay path recover the gap. - connector gains send(); native connector forwards to WebSocket.send - pong messages are parsed and handled silently - any incoming traffic counts as liveness - watch --debug now logs realtime connect/reconnect/auth/warning lifecycle to .wspc-drive/debug.log for future diagnosis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題
wspc drive watch的 realtime WebSocket 被 NAT / edge 默默斷掉(沒有 FIN)時,client 的 WebSocket 永遠不會觸發close,就一直掛在死 socket 上等事件。結果:從 MCP 更新檔案後本地不同步,直到使用者手動 pause/resume 才補下來。實測案例 socket 早在 30 分鐘前就死了,該時段 debug.log 完全沒有realtime_event。修正
{"type":"ping"},10s 內沒有任何流量就主動關閉 socket,走既有 reconnect(帶 cursor)→ server replay → sync,斷線期間的變更不會遺失。逾時錯誤標記為realtime error (PING_TIMEOUT),log 可辨識。send();native connector forward 到WebSocket.send。pong;任何 incoming 流量都算 liveness。watch --debug現在把 realtime connect / reconnect / auth failed / warning 生命週期寫進.wspc-drive/debug.log(這次調查缺的就是這段)。睡眠行為
client ping 是 Node
setTimeout,不會喚醒睡眠中的電腦;睡眠時 timer 暫停,喚醒後才觸發 → 送 ping → socket 已死 → 10s 後重連補齊。server 端 DO 的 pong auto-response 也不喚醒 hibernated DO。相關
需搭配 wspc/wspc#847(server 連線時 replay cursor 之後的事件)才完整:本 PR 負責偵測死 socket 並重連,那邊負責重連後補齊 gap。
測試
npm test521 passed(TDD:新增 3 個 keepalive/pong 測試先跑紅再實作),typecheck 過。