Skip to content

fix: race condition in writeStats#711

Merged
valscion merged 2 commits intowebpack:mainfrom
colinaaa:main
Mar 2, 2026
Merged

fix: race condition in writeStats#711
valscion merged 2 commits intowebpack:mainfrom
colinaaa:main

Conversation

@colinaaa
Copy link
Contributor

@colinaaa colinaaa commented Mar 2, 2026

Summary

Fix a race condition that the writeStats would resolve before the FS operation finished, which may lead to incorrect content in stats.json.

Now instead of manually listen to the end and error event, we use the pipeline API from node:stream/promise to handle error and promise resolving for us. The pipeline API has been added in Node.js v15.0.0, which should work since we have engines.node >= 20.9.0 now.

What kind of change does this PR introduce?

a fix

Did you add tests for your changes?

Yes. And the test would fail without the fix.

Does this PR introduce a breaking change?

No.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

Nothing.

Use of AI

Yes. We use AI to find the race condition in writeStats function and use AI to generate the fix and the test.

I've read and understanded every line of the code I submitted.

@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.30%. Comparing base (3710653) to head (880de30).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #711      +/-   ##
==========================================
+ Coverage   71.60%   76.30%   +4.69%     
==========================================
  Files          17       17              
  Lines         979      979              
  Branches      357      357              
==========================================
+ Hits          701      747      +46     
+ Misses        242      205      -37     
+ Partials       36       27       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@valscion valscion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Would you be so kind and write a changelog entry under the UNRELEASED section and this this as a bug fix?

@colinaaa
Copy link
Contributor Author

colinaaa commented Mar 2, 2026

Looks good to me! Would you be so kind and write a changelog entry under the UNRELEASED section and this this as a bug fix?

Sure!

@valscion valscion merged commit b3f44b0 into webpack:main Mar 2, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants