fix(drive): stop realtime cursor writes from warning during a sync#82
Merged
Conversation
`drive watch` logged a bare "realtime warning: realtime error" ~1s after every upload cycle: the own-echo library_changed arrives mid-sync, so writeDriveRealtimeState's withDriveLock collides with the sync still holding sync.lock and throws "sync lock already exists". redaction then flattened that undiagnosable message to "realtime error". - withDriveLock gains an opt-in bounded retry (DriveLockOptions); sync and ensureDriveRealtimeState keep fail-fast (retries default 0) - writeDriveRealtimeState opts into ~2s of retry so a tiny best-effort cursor write waits out a sync instead of surfacing a warning - lock-contention error now carries code WSPC_DRIVE_LOCK_HELD, so any residual warning redacts to "realtime error (WSPC_DRIVE_LOCK_HELD)"
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每次上傳週期(syncing 0 / 1)約 1 秒後都會噴一行realtime warning: realtime error,看起來像出錯但其實沒事。連鎖反應:存檔觸發一次 sync,sync 握著
.wspc-drive/sync.lock並改寫state.json;同一時間 server 回傳自己造成的 own-echolibrary_changed,只需推進 cursor。但推 cursor 的writeDriveRealtimeState→withDriveLock要搶同一把鎖,撞到 sync 正握著,於是丟sync lock already exists。這個 best-effort 錯誤被redactedRealtimeError壓成毫無資訊的realtime error。兩層問題:cursor 寫入在 sync 進行中會失敗(本來只是暫時撞鎖),且失敗訊息被 redact 到看不出原因。
修正
withDriveLock新增選用的DriveLockOptions,支援 bounded retry。預設retries: 0,所以 sync 與ensureDriveRealtimeState行為不變(撞鎖仍 fail-fast)。writeDriveRealtimeStateopt-in 重試約 2 秒,讓這個 best-effort cursor 寫入等 sync 放鎖後成功,而不是噴警告。code: WSPC_DRIVE_LOCK_HELD,任何殘餘警告會 redact 成realtime error (WSPC_DRIVE_LOCK_HELD),一眼可診斷。cursor 推進本來就是 best-effort、idempotent:就算漏一次,下一個 realtime 訊息或重連 replay 會補回,不掉資料,所以不需要把 realtime 與 sync 寫入全域序列化。
測試
TDD:先寫 4 個紅測試(帶 code、retry 撞鎖後成功、retry 用完仍失敗、cursor 等 sync 放鎖後成功)確認失敗,再實作到全綠。整個 drive 測試 242 passed,
typecheck乾淨。