Fix OOM when allEventsUpToLockProcessed buffer equals MaxRetries()#1666
Merged
meiji163 merged 1 commit intogithub:masterfrom Apr 30, 2026
Merged
Conversation
87754d5 to
9956f87
Compare
PR github#1637 buffered allEventsUpToLockProcessed to MaxRetries() to prevent a goroutine deadlock when waitForEventsUpToLock times out during cutover. However, when --default-retries is set to a very large value (e.g. 9999999999999), Go tries to allocate a channel with trillions of buffer slots, causing an immediate OOM crash before the migration even starts. Replace the MaxRetries()-sized buffer with a buffer of 1 and overwrite-oldest (latest-wins) send semantics. When the buffer is full (receiver timed out on a previous attempt), the stale message is drained before sending the current sentinel. This guarantees: - The current sentinel is always delivered (no message loss) - The executeWriteFuncs worker is never blocked (no deadlock) - Memory usage is constant regardless of MaxRetries() (no OOM) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
9956f87 to
7fd3640
Compare
meiji163
approved these changes
Apr 30, 2026
Contributor
|
LGTM 👍 |
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.
Problem
PR #1637 buffered
allEventsUpToLockProcessedtoMaxRetries()to prevent a goroutine deadlock whenwaitForEventsUpToLocktimes out during cutover. However, when--default-retriesis set to a very large value (e.g.9999999999999), Go tries to allocate a channel with trillions of buffer slots, causing an immediate OOM crash before the migration even starts.Crash
Fix
Replace the
MaxRetries()-sized buffer with a buffer of 1 and overwrite-oldest (latest-wins) send semantics.When the buffer is full (receiver timed out on a previous attempt), the stale message is drained before sending the current sentinel:
This guarantees:
executeWriteFuncsworker never blocks — the send is always non-blockingMaxRetries()Why drop-newest would be wrong
A naive non-blocking send (
select { default: }) would drop the current sentinel when the buffer is full. SincewaitForEventsUpToLockonly succeeds on an exact challenge match, dropping the current message causes a false timeout — potentially while the table is locked during two-step cutover.Overwrite-oldest avoids this: the stale message (which would only be skipped by the receiver anyway) is drained to make room for the current one.
Tests
MaxRetries()to9999999999999and verifiesNewMigratorsucceeds with channel capacity 1