-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Writable stream is not immediatly closed after .destroy() call #31776
Comments
@nodejs/streams |
@addaleax, the link you provided doesn't work... |
I think this is a bug in node/lib/internal/fs/streams.js Lines 368 to 372 in 0875837
to if (this.autoClose) {
this.destroy(callback);
} else {
callback();
} Essentially we are not waiting to close the handle before emitting |
cc @ronag |
Sorry, not perfect in English, did you mean we should neither call The documentation says:
I guess during the call to await pipeline(src, dest);
// Notice, no call to .destroy(), not waiting for "close" here, we go use the copied file right away
spawnSync("dest.exe", ["--version"])); |
I’m saying that you have found a bug in node core ;). The stream is emitting ‘finish’ before the handle is destroyed, and it shouldn’t. |
WriteStream autoClose was implemented by manually calling .destroy() instead of using autoDestroy and callback. This caused some invariants related to order of events to be broken. Fixes: nodejs#31776
@mcollina, sure, I am glad that we spotted a bug! await stream.pipeline(src, dest);
return new Promise(resolve => {
dest.on("close", resolve); // resolve only when "close" is emited
dest.destroy();
}); |
You would not need to call destroy.
await stream.pipeline(src, dest); |
@ronag, will this fix be backported to |
WriteStream autoClose was implemented by manually calling .destroy() instead of using autoDestroy and callback. This caused some invariants related to order of events to be broken. Fixes: nodejs#31776 PR-URL: nodejs#31790 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Backport-PR-URL: nodejs#32163
WriteStream autoClose was implemented by manually calling .destroy() instead of using autoDestroy and callback. This caused some invariants related to order of events to be broken. Fixes: #31776 Backport-PR-URL: #32163 PR-URL: #31790 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
64-bit (Windows 10 Education version 1809)
,Linux lenovo520 4.15.0-70-generic #79-Ubuntu SMP Tue Nov 12 10:36:11 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
fs
,stream
What steps will reproduce the bug?
Run this code with
node
How often does it reproduce? Is there a required condition?
It doesn't reproduce on all platforms stably. On my laptop it does always reproduce on Windows 10. I am not sure what is the required condition for this...
What is the expected behavior?
As per documentation of
.destroy()
:I expect write-stream to release the file handle during the call to
.destroy()
, so that the next call tospawnSync
of the copied file does execute the binary successfully.What do you see instead?
Windows 10 x64
Ubuntu 18.04.3
Additional information
The original problem was when downloading a binary executable from GitHub releases for
rust-analyzer
. You can see the initial discussion on the bug here.The workaround for this that we use now is to wait for
"close"
event on writable-stream after the call to.destroy()
, i.e.The text was updated successfully, but these errors were encountered: