fix(@angular/build): avoid race condition in sass importer #28630
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.
PR Checklist
Please check to confirm your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #27167
Builds under load sometimes fail with "Can't find stylesheet to import" errors.
I was able to reproduce this error in my CI pipeline consistently, by running 4
npx ng build
builds in parallel on an 8 core VPS. It also occurs sometimes during regular builds/ng test
, especially when other concurrent jobs put load on the system.By adding lots and lots of logging, I found the root cause, which is a race condition when the sass worker manages to call
findFileUrl
again in betweenAtomics.store(..., 0, 1)
andAtomics.notify(..., 0)
invocations - I left more details as a comment.What is the new behavior?
The race no longer causes failing builds. After being notified, the worker checks again that the signal is not set to 0, and waits for another
notify
if necessary, which will be the correct one.Does this PR introduce a breaking change?
Other information
I verified that the second
Atomics.wait(..., 0, 0)
actually does something meaningful, by logging the return value. Under load, I observed two instances where the return value was"ok"
, indicating that the signal was 0 at the time of the secondwait
, and the build would therefore have aborted without the change.