fix: close WAL torn-record window in Append(), handle torn tails in Replay() (PILOT-82)#2
Open
matthew-pilot wants to merge 2 commits into
Open
fix: close WAL torn-record window in Append(), handle torn tails in Replay() (PILOT-82)#2matthew-pilot wants to merge 2 commits into
matthew-pilot wants to merge 2 commits into
Conversation
added 2 commits
May 28, 2026 02:49
…Replay() Append() previously wrote the 4-byte length prefix and the data payload as two separate Write() calls — a crash between them left a valid length on disk with no corresponding data. Replay() then hit io.ReadFull on the missing data and returned a hard error, blocking recovery startup. Changes: - Append() now allocates a combined [4-byte len][data] buffer and writes it in a single Write() call, narrowing the crash window to one syscall - Replay() now treats io.EOF / io.ErrUnexpectedEOF on the data read as a torn tail from a partial write, breaking cleanly and returning the entries replayed so far rather than failing the entire recovery Backward-compatible with existing WAL files (format unchanged). Closes PILOT-82
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
What failed
wal/wal.goAppend() wrote the 4-byte length prefix and the data payload as two separateWrite()calls. A crash/power-loss between them left a valid length on disk with no corresponding data — a torn tail. Replay() then hitio.ReadFull()on the missing data and returned a hard error, which could prevent the rendezvous server from starting after recovery.Why this fix
[4-byte len][data]buffer and writes it in a singleWrite()call, narrowing the crash window to one syscall boundary.io.EOF/io.ErrUnexpectedEOFon the data read as a torn tail from a partial write — breaks cleanly and returns the entries replayed so far rather than failing the entire recovery.Verification
go build ./...— cleango vet ./...— cleango test ./...— all 19 packages pass, 0 regressionsTestWALReplayTornTailconfirms recovery from a truncated WALScope
wal/wal.go): +14/-6 functional lineswal/zz_wal_test.go): +57 lines (new test)Closes PILOT-82