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

Writable does not check if stream has been destroyed during _final and _write #39030

Open
ronag opened this issue Jun 14, 2021 · 12 comments · May be fixed by #41164
Open

Writable does not check if stream has been destroyed during _final and _write #39030

ronag opened this issue Jun 14, 2021 · 12 comments · May be fixed by #41164

Comments

@ronag
Copy link
Member

@ronag ronag commented Jun 14, 2021

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.

@ronag ronag changed the title Writable does not check if stream has been destroyed after during _final and _write Writable does not check if stream has been destroyed during _final and _write Jun 14, 2021
@targos targos assigned targos and unassigned targos Aug 9, 2021
@targos targos added the stream label Aug 9, 2021
@targos
Copy link
Member

@targos targos commented Aug 9, 2021

@mcollina
Copy link
Member

@mcollina mcollina commented Aug 9, 2021

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 'error'?

@ronag
Copy link
Member Author

@ronag ronag commented Aug 9, 2021

I think:

  1. cancel any further substeps
  2. if stream was destroyed without error, override with error

@mcollina
Copy link
Member

@mcollina mcollina commented Aug 9, 2021

Should we tag this as good first issue?

@mdaj06
Copy link

@mdaj06 mdaj06 commented Aug 12, 2021

@ronag Can i take this up?

@mcollina
Copy link
Member

@mcollina mcollina commented Aug 12, 2021

Go for it!

@Svanazar
Copy link

@Svanazar Svanazar commented Sep 3, 2021

Hey! I was wondering about the status of this issue, and if I could try looking into it?

@mcollina
Copy link
Member

@mcollina mcollina commented Sep 5, 2021

Go for it!

@Svanazar
Copy link

@Svanazar Svanazar commented Sep 6, 2021

I went through Writable.js, but I'm not sure where should the checks be added. Specifically, I found these to be already present:

  • _write at line 321 checks for state.destroyed before going to the user-provided _write function
  • _final seems to be called through prefinish which also checks for state.destroyed at line 718

I'll really appreciate some guidance on this

@ronag
Copy link
Member Author

@ronag ronag commented Sep 7, 2021

You need to look at the time between those being called and their callback being invoked.

@Svanazar
Copy link

@Svanazar Svanazar commented Sep 10, 2021

Thanks! I followed the code between these two times, and wanted to confirm the location. For _write, will it be appropriate to place the check inside onwrite() ?

This will be for the case when the stream gets destroyed during _write but no error is passed to the callback.

@rscherich
Copy link

@rscherich rscherich commented Nov 16, 2021

After looking into this, this seems to run counter to a previous pull request (maybe I didn't understand something?): #24062
Of course, the project requirements might have changed since then too.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

6 participants