fix(memiavl): bound the WAL catch-up wait instead of spinning forever - #80
Conversation
checkBackgroundSnapshotRewrite busy-waited with no timeout for the wal to catch up to the last committed version, while holding db.mtx. If the async wal writer goroutine died or got stuck, this would spin forever, burning CPU and deadlocking the whole DB. Extract the wait into waitCommittedVersion with a bounded timeout that returns an error instead of blocking indefinitely.
Signed-off-by: JayT106 <JayT106@users.noreply.github.com>
|
Claude finished @JayT106's task in 1m 21s —— View job PR Review
SummaryThis is a clean, well-scoped fix. The unbounded Issues FoundOne functional bug (inline comment posted): CodeQL Alerts (non-blocking)The two Minor Observations
VerdictApprove with one suggestion: fix the |
Equality check could spin until timeout if the wal advances past the target version between polls under concurrent commits.
Poll interval of 1ms added up to 1ms latency per wait call, ~1000x the actual wal append time. Drop to 1us.
|
Claude finished @JayT106's task in 55s —— View job Follow-up Review
All Previous Issues Resolved ✓The two issues from the first review have both been fixed: 1. 2. New test for the Current State
Minor ObservationThe poll interval is VerdictLGTM. The fix is correct, minimal, and well-tested. Ready to merge. |
# Conflicts: # CHANGELOG.md # memiavl/db.go # memiavl/db_test.go
What
memiavl/db.go:checkBackgroundSnapshotRewrite's unbounded busy-wait loop is replaced withwaitCommittedVersion(targetVersion int64, timeout time.Duration) error, bounded by new constantswalCatchupTimeout(5s) andwalPollInterval(50ns).Issue
The loop spun with no timeout waiting for the committed version to catch up, so a stuck writer or unreachable target version hung the caller forever.
Solution
Returns a timeout error instead, propagated through the existing
checkAsyncTasks→errors.Join→Commit()chain with no signature changes elsewhere. ConfirmedCommittedVersion()doesn't re-lockdb.mtx, so no self-deadlock is introduced by polling it.Test
TestWaitCommittedVersionTimesOut,TestWaitCommittedVersionSucceedsWhenCaughtUp.go test -race ./...,gofmt -l,golangci-lint runall clean.