Skip to content
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

createWriteStream: Ignore error in fs.unlinkSync #8616

Draft
wants to merge 1 commit into
base: v2
Choose a base branch
from

Conversation

mischnic
Copy link
Member

@mischnic mischnic commented Nov 9, 2022

Looks like Node's fs.createWriteStream sometimes fails to create a file at all, which would mean that unlinkSync() tries to delete a file that doesn't exist resulting in the error. (Or maybe there's a writestream error after the file was renamed?)

I don't know though why it happens only rarely on Windows and apparently nowhere else.

Closes #8571
Closes #8615

@parcel-benchmark
Copy link

parcel-benchmark commented Nov 9, 2022

Benchmark Results

Kitchen Sink ✅

Timings

Description Time Difference
Cold 1.83s +19.00ms
Cached 411.00ms -9.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 308.00ms +200.00ms ⚠️
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 307.00ms +198.00ms ⚠️
dist/modern/parcel.7cdb0fad.webp 102.94kb +0.00b 307.00ms +199.00ms ⚠️

React HackerNews ✅

Timings

Description Time Difference
Cold 11.65s +114.00ms
Cached 508.00ms -16.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

AtlasKit Editor ✅

Timings

Description Time Difference
Cold 2.10m +841.00ms
Cached 2.62s +102.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

Three.js ✅

Timings

Description Time Difference
Cold 8.23s +6.00ms
Cached 336.00ms -33.00ms 🚀

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

Click here to view a detailed benchmark overview.

@partyvaper
Copy link

@mischnic I was having similar issues, and after applying your fix as a yarn patch it got better but still got this error:

× Build failed.

@parcel/compressor-raw: EPERM: operation not permitted, rename D:\test\dist\index.html.12768.5c' -> 'D:\test\dist\index.html'

  Error: EPERM: operation not permitted, rename 'D:\test\dist\index.html.12768.5c' -> 'D:\test\dist\index.html'

Does this solution work perfectly or still has some issues?

@mischnic
Copy link
Member Author

mischnic commented Dec 9, 2022

No, that should not be happening.

Previously, it would have tried to delete D:\test\dist\index.html.12768.5c but after my change, that error was silence. And now it tries to use that file somewhere else. So the question is why that file wasn't created in the first place

@partyvaper
Copy link

partyvaper commented Dec 9, 2022

@mischnic I havent checked Parcel source that much, but perhaps there are multiple threads running (idk if Parcel is multi-threaded), and something deleted that file already previously? Seems like some kind of race condition.

Now after your intial fix it was way harder for me to get any errors, but still managed to get this one 😅

@mischnic
Copy link
Member Author

mischnic commented Dec 9, 2022

multiple threads

That is exactly the reason why we added this atomic write stream in the past.
For the distdir, multiple threads writing the same file is probably unwanted. But there are other places (writing to cache) where it can still happen

@IMGROOT2
Copy link

@mischnic could we please get a fix on this? It’s been multiple months and I’ve been suffering nonstop since.

@smourier
Copy link

For what it's worth,I have the same problem as @partyvaper above, adding try/catch over unlink fixes this exact issue (I'm on Windows), but then I see another frequently (not always):

🚨 Build failed.

@parcel/compressor-raw: EPERM: operation not permitted, rename 'D:\My\dist\index.6b815632.js.map.10664.a' -> 'D:\My\dist\index.6b815632.js.map'

  Error: EPERM: operation not permitted, rename 'D:\My\dist\index.6b815632.js.map.10664.a' -> 'D:\My\dist\index.6b815632.js.map'

The good news is this new error (that I didn't have before the try/catch) doesn't break the whole parcel process so I can trigger any change (save a file for example, I use the watch command) and it works again. Not super, but better.

@sung92
Copy link

sung92 commented Nov 23, 2023

Hello guys, I am experiencing the same issue, posted the error here: #8571

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.

Parcel Serve 2.8.0 randomly crashes while rebuilding ENOENT error after changing the html file
6 participants