-
Notifications
You must be signed in to change notification settings - Fork 128
fix(web): Fix multiple writes race condition on config file watcher #398
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
Conversation
WalkthroughThe changes update the configuration file watcher in the web package by replacing Node.js's native Changes
Sequence Diagram(s)sequenceDiagram
participant App
participant Chokidar
participant ConfigSync
App->>Chokidar: Start watching config file
Chokidar-->>App: Emits 'change' event after file stabilizes
App->>ConfigSync: Attempt to sync declarative config (async)
ConfigSync-->>App: Success or error (logged)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
This comment has been minimized.
This comment has been minimized.
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: 0
🧹 Nitpick comments (1)
packages/web/src/initialize.ts (1)
230-246
: Excellent implementation to fix the race condition.The chokidar configuration effectively addresses the Docker volume mount race condition issues:
ignoreInitial: true
prevents duplicate events on startupawaitWriteFinish
with 100ms stabilityThreshold ensures file writes are completeatomic: true
handles temp file + rename operations properly- Added error handling prevents crashes from sync failures
Consider these minor enhancements:
const watcher = chokidar.watch(configPath, { ignoreInitial: true, // Don't fire events for existing files awaitWriteFinish: { stabilityThreshold: 100, // File size stable for 100ms pollInterval: 100 // Check every 100ms }, - atomic: true // Handle atomic writes (temp file + rename) + atomic: true, // Handle atomic writes (temp file + rename) + usePolling: false, // Use native events when possible + ignorePermissionErrors: true // Ignore permission errors in Docker }); watcher.on('change', async () => { - logger.info(`Config file ${configPath} changed. Re-syncing...`); + logger.info(`Config file ${configPath} changed, re-syncing declarative config...`); try { await syncDeclarativeConfig(configPath); + logger.info(`Successfully synced declarative config from ${configPath}`); } catch (error) { - logger.error(`Failed to sync config: ${error}`); + logger.error(`Failed to sync declarative config from ${configPath}:`, error); } });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
yarn.lock
is excluded by!**/yarn.lock
,!**/*.lock
📒 Files selected for processing (3)
CHANGELOG.md
(1 hunks)packages/web/package.json
(1 hunks)packages/web/src/initialize.ts
(2 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:
CHANGELOG.md
packages/web/package.json
packages/web/src/initialize.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (3)
packages/web/package.json (1)
114-114
: Chokidar dependency is up-to-date and secureVerified that [email protected] is the latest stable release on npm and no security advisories were found. Approving the addition.
• packages/web/package.json (line 114): "chokidar": "^4.0.3"
packages/web/src/initialize.ts (1)
5-5
: LGTM: Chokidar import added.The import statement is correctly placed and follows the existing import organization pattern.
CHANGELOG.md (1)
13-15
: LGTM: Changelog entry accurately documents the fix.The changelog entry properly documents the race condition fix and follows the established format with the correct PR reference.
When starting up a fresh Docker installation with a empty config file, I hit the following issue when I made a edit to the file:
According to Cursor:
The fix (also suggested by Cursor):
I switched to using chokidar and I am no longer hitting the issue.
Summary by CodeRabbit
Bug Fixes
Chores