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

Readables that close without an 'end' event does not end. #478

Closed
Flygsand opened this issue Apr 14, 2016 · 3 comments
Closed

Readables that close without an 'end' event does not end. #478

Flygsand opened this issue Apr 14, 2016 · 3 comments
Labels

Comments

@Flygsand
Copy link

Consider the following code:

function readFile(name) {
  return _(fs.createReadStream(name));
}

var extra = _([new Buffer('baz')]);

_(['foo', 'bar'])
  .map(readFile)
  .merge()
  .concat(extra)
  .errors(function() { })
  .each(_.log);

If both foo and bar are successfully read, the stream produces three buffers (contents of foo, contents of bar, and extra). If, for example, bar can't be read, the stream produces one buffer (contents of foo). Wouldn't it make more sense for the stream to produce (contents of foo, and extra) in that case?

@vqvu vqvu changed the title Concat with streams containing errors Readables that close without an 'end' event does not end. Apr 14, 2016
@vqvu vqvu added the bug label Apr 14, 2016
@vqvu
Copy link
Collaborator

vqvu commented Apr 14, 2016

You have a knack for finding bugs in our code 😄.

This isn't a concat thing. The fs.createReadStream will close itself when it encounters an error. This means emitting close without emitting end. We weren't listening to the close event, so the wrapper stream thought that the stream had never ended. That's why you didn't see the data from extra. It was waiting for the original foo/bar streams to end and they never did.

@Flygsand
Copy link
Author

Ah :). Kudos again for the quick turnaround.

@vqvu
Copy link
Collaborator

vqvu commented Apr 15, 2016

I take back what I said above. In the case where you try to open an non-existent file, you don't end getting a close at all. You just get a single ENOENT error. close only fires if the file was successfully opened but there was an error reading from it. Same class of bug though.

@vqvu vqvu closed this as completed in c8177fb Apr 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants