Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary by cubic
Prevent idle self-kill restarts while migration jobs are running to avoid interrupting migrations. We now track active migration jobs and only recycle the worker when idle and no migrations are active.
Written for commit beaa71d. Summary will update on new commits.
Greptile Summary
This PR fixes a race condition where the SQS worker's idle self-kill logic could terminate the process while long-running migration jobs were still executing in the background.
Key Changes:
activeMigrationJobscounter that is incremented before dispatching a migration job as fire-and-forget, and decremented in.finally()after it settles. ThelogStatsAndCheckZeroMessagesidle self-kill condition now additionally requiresactiveMigrationJobs === 0before callingprocess.exit(0), preventing premature worker termination during in-flight migrations.Confidence Score: 5/5
.finally()block guarantees the decrement runs regardless of success or failure. The added condition at the idle self-kill check precisely targets the problematic code path where migrations could be killed mid-flight. The implementation is straightforward with no edge cases in the core fix.Sequence Diagram
sequenceDiagram participant SQS participant PollLoop as Polling Loop participant Counter as activeMigrationJobs participant Handler as handleSingleMessage participant Stats as logStatsAndCheckZeroMessages SQS->>PollLoop: Message received (JobName.Migration) PollLoop->>Counter: activeMigrationJobs++ (now > 0) PollLoop->>Handler: fire-and-forget (no await) PollLoop->>SQS: continue polling Note over Stats: setInterval (every 60s) Stats->>Stats: messagesProcessed === 0? Stats->>Counter: activeMigrationJobs === 0? alt activeMigrationJobs > 0 Stats-->>Stats: Skip idle self-kill (migration running) else activeMigrationJobs === 0 Stats-->>Stats: process.exit(0) if idle threshold met end Handler-->>Handler: processMessage completes Handler->>Counter: activeMigrationJobs-- via .finally()Last reviewed commit: beaa71d