You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fs.createWriteStream can cause out-of-order writes, in v18.16+ #51993
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
helloworld
What do you see instead?
worldhello
Additional information
The issue was caused by this change: #46818, which landed in node v18.16.0 and v19.8.0.
(Thanks to @Fadorico for tracking down this change. I have also confirmed this by building node locally.)
This is causing the 'unzipper' module to create corrupted files, because its 'fstream' dependency uses fs.createWriteStream() like in the example above.
It looks like when the stream's "open" event fires, the stream does not yet have the "constructed" flag set, so that might be why things are getting weird.
As a workaround, if I wait an additional tick after the "open" event, there are no issues:
changed the title [-]fs.createWriteStream can cause out-of-order writes, in v18.16+ and v19.8+[/-][+]fs.createWriteStream can cause out-of-order writes, in v18.16+[/+]on Mar 6, 2024
Activity
[-]fs.createWriteStream can cause out-of-order writes, in v18.16+ and v19.8+[/-][+]fs.createWriteStream can cause out-of-order writes, in v18.16+[/+]benjamingr commentedon Mar 7, 2024
@mcollina @ronag
mcollina commentedon Mar 7, 2024
I'm sorry it caused a regression this far down. Will patch it. Hopefully we can backport the fix to v18.
fs: defer the writestream 'open' event by a nextTick
stream: do not defer construction by one microtick
stream: do not defer construction by one microtick
stream: do not defer construction by one microtick
stream: do not defer construction by one microtick
dy-dx commentedon Mar 26, 2024
I can confirm the issue has been fixed in the following node.js versions: