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

Writeable stream .end() has paradoxical logic #5540

Closed
ronkorving opened this issue Mar 3, 2016 · 9 comments
Closed

Writeable stream .end() has paradoxical logic #5540

ronkorving opened this issue Mar 3, 2016 · 9 comments
Labels
question Issues that look for answers. stream Issues and PRs related to the stream subsystem.

Comments

@ronkorving
Copy link
Contributor

  • Version: 5.7.1
  • Platform: all
  • Subsystem: streams

It says here to ignore unnecessary end() calls. That means callbacks will not fire, even though end() is called. Should it not instead return either an error to the callback, or act as a noop before calling cb? The irony is that endWritable itself seems to act exactly like it may be called multiple times.

So which should it be? Right now, it seems like we have 2 different pieces of reasoning in the same class, and one simply overrules the other. Imho, we should get rid of one, and in my opinion, it should be the "ignore unnecessary end() calls" one, because when people pass a callback, they expect it to be called.

@ronkorving ronkorving changed the title Writeable stream .end() has double logic Writeable stream .end() has paradoxical logic Mar 3, 2016
@mscdex mscdex added question Issues that look for answers. stream Issues and PRs related to the stream subsystem. labels Mar 3, 2016
@Fishrock123
Copy link
Contributor

cc @nodejs/streams

@mcollina
Copy link
Member

mcollina commented Mar 4, 2016

I would say send a PR and we'll evaluate how many modules break :/. However all the writes and ends callbacks may not fire (as of now). This definitely improves the situation, but it's not the full solution.

@calvinmetcalf
Copy link
Contributor

That logic in endWritable actually has to do with whether finishMaybe was able to finish the stream up or whether their were still pending async things.

This will actually only come up if end is called without any data, if it's called with data then it will through an error. In theory yes having it through an error would be good, it would be a breaking change which would likely be bad.

@jasnell
Copy link
Member

jasnell commented May 30, 2017

ping @nodejs/streams

@mcollina
Copy link
Member

I will put this into our next wg meeting agenda. So that we can decide what's the right path.

@mcollina
Copy link
Member

I think the problem here is that the callback to end() might not be called. That looks like a bug to me.

@Trott
Copy link
Member

Trott commented Aug 7, 2017

Should this remain open?

@mcollina
Copy link
Member

mcollina commented Aug 8, 2017

Yes, I think so.

@mcollina
Copy link
Member

mcollina commented Sep 12, 2017

Ideally we would love to fix it, but it will cause too much breakages at this point in a lot of modules.
There is a lot of code out there that calls .end() multiple times, including .pipe().

You can use http://npm.im/pump or https://www.npmjs.com/package/end-of-stream to know if a stream has ended. We are porting those over in #13506.

cc @nodejs/streams

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

No branches or pull requests

7 participants