-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Stream not emitting data event after pipe+unpipe #1041
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
you should get the error "chunk is not defined" on line 6, when fixed it should print "ok" on the stdout. |
I'm sorry @micnic I forgot the chunk argument when I wrote this snipet I've modified the line. var stream = require('stream');
var pass = new stream.PassThrough();
var writable = new stream.Writable();
// When the line below is commented, ok is logged
//pass.pipe(writable); pass.unpipe(writable);
pass.on('data', function(chunk){ console.log(chunk.toString()); });
pass.write('ok'); |
|
You're right ! With 0.10 no need to call resume() var stream = require('stream');
var pass = new stream.PassThrough();
var writable = new stream.Writable();
pass.pipe(writable); pass.unpipe(writable);
pass.resume();
pass.on('data', function(chunk){ console.log(chunk.toString()); });
pass.write('ok'); Thank you very much :) |
|
ping @iojs/streams |
@chrisdickinson This "feature" seems to have been introduced here 444bbd4
I believe this was during the We'll have to see what the implications are to streams with only a |
@sonewman @chrisdickinson @nodejs/streams I don't suppose there's anything new to add to this issue at this time, is there? |
That's a bug indeed, tracked down in the following: var fs = require('fs');
var src = fs.createReadStream(__filename);
var dst = fs.createWriteStream('/tmp/test');
src.pipe(dst);
src.unpipe(dst);
src.on('data', function() {
console.log("Never happens")
}); As @chrisdickinson wrote above, P.S. And yes, extra |
This sounds like it may just be a docs issue? |
yes, it's a docs issue, there's another one I remember, explicitly citing docs. Maybe close this one. |
at least, it looks like the code won't be fixed, so it becomes a docs issue ;) |
ping @nodejs/streams |
It is a doc issues, specifically we need to update https://nodejs.org/api/stream.html#stream_three_states so that it clearly states things. |
Clarifies the behavior of streams when _readableState.flowing is false. resume() must be called explicitly for the 'data' event to be emitted again. Fixes: nodejs#1041
Fixed in 0b432e0. |
Actually, this still breaks any Consider the following: const readable; // A Readable stream
const writable; // A Writable stream
readable.on('data', function onData(chunk) {
// This will only execute until unpipe();
});
readable.pipe(writable);
readable.unpipe(writable); Given it unexpectedly pauses the stream, even while there are In scenarios where there are two independent algorithms consuming the stream - the first using For the scenario I mentioned here, I've already created a quick fix (and associated test), but I'm waiting for your thoughts before turning it into a PR. The fix simply checks if there are any remaining A similar argument could be made for attaching |
It is a doc issue compared to the current behavior: streams currently behave in this way, and it is expected for them to keep behaving in this manner as the commit you are referencing is 5 years old. You are proposing a change to this behavior which will be semver-major and I expect it to be a non-trivial change, considering possible breakages in userland. |
@mcollina many thanks for clarifying why it's been a doc issue. |
The following should log 'ok' to the console but nothing is logged.
Of course, commenting the line
pass.pipe(writable); pass.unpipe(writable);
fix the problem.Can you explain me why?
The text was updated successfully, but these errors were encountered: