-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
stream: Support writing null to stream.Transform #5729
Conversation
As discussed in nodejs#5711, writing null to a stream.Transform puts the stream into an unrecoverable state. This commit fixes the issue by passing it to ._transform, like the other falsey values. It updates the falsey value test for Transform to include null (and undefined, which was previously omitted) and adds a test for the behavior of Writable in objectMode when falsey values are written to match Transform. Fixes: nodejs#5711
Does this mean that non- |
The changes in this PR don't affect non- Currently calling |
Looking closer, |
Roll another PR. We should probably run this on citgm (https://github.com/nodejs/citgm) before landing, just in case. |
@mcollina Sure, can't hurt. Is there a build farm which runs citgm? Is there anything I need to do to schedule a run? |
Not sure. Any idea @mafintosh @calvinmetcalf? |
@thealphanerd set up a job in ci.nodejs.org that runs citgm. I'm sure he can help get you going with it. |
@@ -162,7 +162,7 @@ Transform.prototype._write = function(chunk, encoding, cb) { | |||
Transform.prototype._read = function(n) { | |||
var ts = this._transformState; | |||
|
|||
if (ts.writechunk !== null && ts.writecb && !ts.transforming) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what was the original rational for this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
26ca7d7 describes it as "null is reserved to indicate stream eof". Perhaps the author confused .write(null)
with .push(null)
, or planned for .write(null)
to cause EOF? Or they intended to disallow .write(null)
to avoid confusion about it being interpreted as EOF in other contexts? I'm not exactly sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change also means that writing null to a passthrough will end the readable side which is a bit weird
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change also means that writing null to a passthrough will end the readable side
I don't think so. null
and undefined
are ignored by the ._transform
callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah cool. didn't know that.
Thanks @thealphanerd! |
Quite a few failures, we should probably have a closer look at them. |
Thinking about this, there is a good reason why you cannot pass stream.write(null) -> stream._transform(null, '', cb) -> this.push(null) -> the stream closes For simmetry, we might even remove writing null to a Writable. However, we should support the other falsey values (like undefined). |
Indeed. I can open a new PR which ignores, throws, or emits an error for
My vote is for the last option. In an ideal world, I would like to change |
@kevinoid I'm not understanding all the various options you are laying out. Can you please clarify? I think we should emit/callback an |
@mcollina Sure, that will work. I disagree that the writer continuing is unlikely, since I think there is a lot of code in the wild which doesn't properly check for write errors. But I'm not opposed to that option. Stated somewhat differently (in the same order), the three options I see are:
Should I open a PR to implement option 2, as you suggested, or hold off until after it is discussed at the WG meeting? |
I'm ok for option 2. Calvin? Il giorno gio 31 mar 2016 alle 20:19 Kevin Locke [email protected]
|
at the readable stream meeting yesterday we decide on 2 so I'll open a pull for that |
Sounds good, thanks @calvinmetcalf! |
Here's a proposed fix for #5711, which passes
null
to._transform
, like other falsey values.It updates the falsey value test for
Transform
to includenull
(andundefined
, which was previously omitted) and adds a test for the falsey value behavior ofWritable
inobjectMode
, as requested in #5711 (comment)Let me know what you think @mcollina and @calvinmetcalf (and anyone else interested, of course).
Fixes: #5711