next.js
4345504b - fix: avoid race condition when download swc wasm (#58536)

Commit
2 years ago
fix: avoid race condition when download swc wasm (#58536) ### What? I noticed that code that was responsible for download the SWC Wasm fallback wasn't bullet proof and there was a chance for a race condition. The reason was that both `write` and `close` from a write stream are async operations and it's best to wait for them to complete, otherwise the promise returned from `body.pipeTo` could resolve before all data has been written and the stream was closed. Right after that it calls `rename` and it could happen that, at that point, `tempFile` doesn't contain all the data yet which means an empty file may be renamed into another file ending up with `path.join(cacheDirectory, tarFileName)` being empty as well. The fix is to wait for both `write` and `close` to be completed which eliminates the potential race condition between the fetch and the rename. Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Author
Parents
Loading