-
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
Writable does not check if stream has been destroyed during _final and _write #39030
Comments
@nodejs/streams |
I don't know to be honest as I don't want to make things too stringent. However adding a check is going to improve the developer experience. What should the check do? Throw? emit |
I think:
|
Should we tag this as good first issue? |
@ronag Can i take this up? |
Go for it! |
Hey! I was wondering about the status of this issue, and if I could try looking into it? |
Go for it! |
I went through Writable.js, but I'm not sure where should the checks be added. Specifically, I found these to be already present:
I'll really appreciate some guidance on this |
You need to look at the time between those being called and their callback being invoked. |
Thanks! I followed the code between these two times, and wanted to confirm the location. For This will be for the case when the stream gets destroyed during |
After looking into this, this seems to run counter to a previous pull request (maybe I didn't understand something?): #24062 I can't immediately see a way to throw an error at the start of the callbacks without changing/removing several of the tests. I also foresee some issues with asynchronous implementations of _write and _final (also in the tests). Do we want to go ahead with the change anyway? |
These tests were dependent on Node.js streams error handling behavior which has changed. Namely, Writeable would previously throw an error when calling write on a closed stream. The only thing that Node seems to do reliably across versions is return false if the write failed and pass the error to the write callback. There is an open issue to once again throw an error for write-after-destroy (although not for write-after-end): nodejs/node#39030 In Node 16 the behavior for write-after-{end|destroy} when there is no listener for the `error` event is to throw an uncaughtException. This is hard/janky to catch for test purposes and anyway only really tests Node's internal code, not our code. So I removed those tests and instead tightened up the tests for the case when there is an `error` handler registered.
These tests were dependent on Node.js streams error handling behavior which has changed. Namely, Writeable would previously throw an error when calling write on a closed stream. The only thing that Node seems to do reliably across versions is return false if the write failed and pass the error to the write callback. There is an open issue to once again throw an error for write-after-destroy (although not for write-after-end): nodejs/node#39030 In Node 16 the behavior for write-after-{end|destroy} when there is no listener for the `error` event is to throw an uncaughtException. This is hard/janky to catch for test purposes and anyway only really tests Node's internal code, not our code. So I removed those tests and instead tightened up the tests for the case when there is an `error` handler registered.
When I went through |
Seems to be an interesting research topic. |
Hey i was wondering if this issue is still open and if i can take a crack at it 😸 |
Hi, is this issue still open. If so, I can try and resolve it. |
This would also be my first issue if I am able to work on it. |
Can you assign this issue to me? |
Hi. Is this still open for people to work on? If so is the following the expected behaviour?
|
@mcollina @ronag I think that emitting I've dug into this issue, and I've got some insights to share. Take a look: It seems that throwing ERR_STREAM_DESTROYED is the behavior the PR #45062 is attempting to avoid.. Also, in PR #25973, they tweaked the documentation on destroy. Now it implies that there might be cases where ERR_STREAM_DESTROYED won't be triggered. Previously, it said:
Now:
Upon examining the code, it's apparent that the ERR_STREAM_DESTROYED error occurs when destroy is called while there is still data in the buffer awaiting write. For example:
So, based on what I've seen, I'm thinking we might not need to dive deeper into this issue. I would appreciate your thoughts on this. Cheers! |
Not sure if this is a problem but I think we should at least add a comment in the code that this case has been considered.
The text was updated successfully, but these errors were encountered: