-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
EBADF thrown by stream if file is explicitly closed in v15 #35862
Comments
I think the right way to handle the close it is to wait for the end of the stream: stream.on('end', () => handle.close()); I confirm that the behavior of Node 15 is different from the previous versions, but I think that the behavior in this situation is indeed undefined (@ronag ?), so it is only normal that it changes across different versions. As a funny side note, when you use There is feature request for solving this: #35240 |
Yea, this is in the realm of undefined behavior. We could avoid the undefined behavior if the read stream took the But I think this is actually the correct behavior once it's no longer undefined. |
See #35240 |
On a second thought, reading from another file descriptor, even if the behavior is officially undefined, this is probably a little bit too much
There is a (quite complex) solution possible by reusing the |
I think this can be closed right? When I run the supplied code on Node.js 15.0.1 I do get an error, but when I run it on the latest Node.js 15.x (or any newer version), the script exists without any errors. So I assume it's fixed. |
An unexpected EBADF error is thrown if a stream is open on a file and then the file is explicitly closed.
The explicit
close
call is required if usingfs/promises
, otherwise a warning is emitted.What steps will reproduce the bug?
I've created a simple case that generates the error.
TESTFILE.txt
exists and could be empty.How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
No error.
What do you see instead?
The following error is thrown:
If
autoClose
is omitted ortrue
, the thrown error is:This last error is thrown also if
stream.destroy()
is called beforehandle.close()
.The only way to avoid the error is to not call
handle.close
, but this generates a deprecation warning in a more complex application (Closing a FileHandle object on garbage collection is deprecated.
)Additional information
No error is emitted on previous node versions (10-14).
The text was updated successfully, but these errors were encountered: