- Notifications
You must be signed in to change notification settings - Fork 203
fix(worker): Run setInterval as blocking#607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
brendan-kellam commented Nov 9, 2025 • edited by coderabbitai bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by coderabbitai bot
Uh oh!
There was an error while loading. Please reload this page.
coderabbitaibot commented Nov 9, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis PR fixes a race condition in job schedulers by introducing Changes
Sequence DiagramsequenceDiagram participant Caller participant setIntervalAsync participant isRunning Flag participant Async Task Note over Caller,Async Task: setIntervalAsync prevents concurrent executions rect rgb(230, 245, 250) Note over setIntervalAsync,isRunning Flag: First interval tick Caller->>setIntervalAsync: Interval fires (tick 1) setIntervalAsync->>isRunning Flag: Check isRunning isRunning Flag-->>setIntervalAsync: false setIntervalAsync->>isRunning Flag: Set isRunning = true setIntervalAsync->>Async Task: Await task (500ms) Async Task-->>setIntervalAsync: Task completes setIntervalAsync->>isRunning Flag: Set isRunning = false end rect rgb(255, 240, 245) Note over setIntervalAsync,isRunning Flag: Second interval tick (overlapping) Caller->>setIntervalAsync: Interval fires (tick 2) setIntervalAsync->>isRunning Flag: Check isRunning isRunning Flag-->>setIntervalAsync: true setIntervalAsync->>setIntervalAsync: Return early (skip execution) Note over setIntervalAsync: Prevents race condition end Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This comment has been minimized.
This comment has been minimized.
brendan-kellam commented Nov 9, 2025
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
CHANGELOG.md(1 hunks)packages/backend/src/connectionManager.ts(2 hunks)packages/backend/src/ee/accountPermissionSyncer.ts(2 hunks)packages/backend/src/ee/repoPermissionSyncer.ts(2 hunks)packages/backend/src/repoIndexManager.ts(2 hunks)packages/backend/src/utils.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*
📄 CodeRabbit inference engine (.cursor/rules/style.mdc)
Filenames should always be camelCase. Exception: if there are filenames in the same directory with a format other than camelCase, use that format to keep things consistent.
Files:
packages/backend/src/utils.tspackages/backend/src/repoIndexManager.tsCHANGELOG.mdpackages/backend/src/connectionManager.tspackages/backend/src/ee/accountPermissionSyncer.tspackages/backend/src/ee/repoPermissionSyncer.ts
🔇 Additional comments (9)
CHANGELOG.md (1)
10-12: LGTM - Changelog entry is appropriate.The changelog entry accurately describes the race condition fix and follows the project's changelog format.
packages/backend/src/ee/accountPermissionSyncer.ts (2)
10-10: LGTM - Import is correct.The import path
../utils.jscorrectly references the new utility function.
50-50: LGTM - Correctly prevents overlapping scheduler executions.Replacing
setIntervalwithsetIntervalAsyncensures that if the permission sync query and job scheduling takes longer than 5 seconds, a new execution won't start until the current one completes, preventing the race condition.packages/backend/src/repoIndexManager.ts (2)
15-15: LGTM - Import is correct.The import correctly includes
setIntervalAsyncfrom the utils module.
75-77: LGTM - Correctly prevents overlapping scheduler executions.The changes are well-implemented:
- Removing
asyncfrom the function signature is correct sincestartSchedulerno longer awaits any operations- Using
setIntervalAsyncensures that ifscheduleIndexJobsorscheduleCleanupJobstakes longer than the polling interval, a new execution won't start until the current one completes, preventing the race conditionpackages/backend/src/connectionManager.ts (2)
10-10: LGTM - Import is correct.The import correctly includes
setIntervalAsyncfrom the utils module.
69-69: LGTM - Correctly prevents overlapping scheduler executions.Replacing
setIntervalwithsetIntervalAsyncensures that if the connection sync query and job creation takes longer than the polling interval, a new execution won't start until the current one completes, preventing the race condition.packages/backend/src/ee/repoPermissionSyncer.ts (2)
11-11: LGTM - Import is correct.The import path
../utils.jscorrectly references the new utility function.
51-51: LGTM - Correctly prevents overlapping scheduler executions.Replacing
setIntervalwithsetIntervalAsyncensures that if the repo permission sync query and job scheduling takes longer than 5 seconds, a new execution won't start until the current one completes, preventing the race condition.
Uh oh!
There was an error while loading. Please reload this page.
e70ca49 to 8979c96Compare6f64d5b into mainUh oh!
There was an error while loading. Please reload this page.
setInterval is not blocking, so if a callback takes longer than the polling interval to execute, than we can run into situations where multiple setInterval callbacks run in parallel.
This change adds
setIntervalAsyncthat handles this. See: https://mottaquikarim.github.io/dev/posts/setinterval-that-blocks-on-await/Summary by CodeRabbit
Bug Fixes