-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(core): handle race condition when reading cached project graph #32162
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
When multiple processes call readCachedProjectGraph() simultaneously before the cache exists, they would all fail with "No cached ProjectGraph is available" error. This was common when running parallel builds. The fix adds synchronous waiting when a lock file exists, indicating another process is building the graph. Uses Atomics.wait() for efficient blocking without CPU usage. - Wait up to 120 seconds for graph to be built - Check every 200ms for graph availability - Detect if other process fails (lock removed, no graph) - Provide helpful timeout message with lock cleanup instructions Fixes nrwl#31648 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
View your CI Pipeline Execution ↗ for commit ff92b8d
☁️ Nx Cloud last updated this comment at |
projectGraphCache = readProjectGraphCache(minimumComputedAt); | ||
|
||
// Check if lock still exists | ||
if (!fileExists(lockPath)) { |
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.
The presence of the lock file doesn't actually indicate the graph building. After the first graph is created, the file will always remain on disk. We place an OS read write lock on the file which is the actual indicator
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.
@AgentEnder That's super helpful! So is the correct approach to add wait_sync to FileLock and update readCachedProjectGraph to use it? (this mirrors createProjectGraphAsync logic but sync)
If so I can supply a PR later today
(we're still encountering #31648 in production so are in need of a fix)
…OOO/nx into fix/project-graph-race-condition-v2
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
When multiple processes call readCachedProjectGraph() simultaneously before the cache exists, they would all fail with "No cached ProjectGraph is available" error. This leads to a hard to reproduce race condition that has been reported repeatedly.
The fix adds synchronous waiting when a lock file exists, indicating another process is building the graph. Uses Atomics.wait() for efficient blocking without CPU usage.
No behavior is changed unless the race condition is encountered (a lockfile exists but no project graph).
Fixes #31648