Uh oh!
There was an error while loading. Please reload this page.
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
mscdex
commented
Mar 15, 2016
Does this mean that non- |
kevinoid
commented
Mar 15, 2016
The changes in this PR don't affect non- Currently calling |
kevinoid
commented
Mar 15, 2016
Looking closer, |
mcollina
commented
Mar 16, 2016
Roll another PR. We should probably run this on citgm (https://github.com/nodejs/citgm) before landing, just in case. |
kevinoid
commented
Mar 16, 2016
@mcollina Sure, can't hurt. Is there a build farm which runs citgm? Is there anything I need to do to schedule a run? |
mcollina
commented
Mar 16, 2016
Not sure. Any idea @mafintosh@calvinmetcalf? |
jasnell
commented
Mar 16, 2016
@thealphanerd set up a job in ci.nodejs.org that runs citgm. I'm sure he can help get you going with it. |
| Transform.prototype._read = function(n) { | ||
| var ts = this._transformState; | ||
| if (ts.writechunk !== null && ts.writecb && !ts.transforming) { |
There was a problem hiding this comment.
what was the original rational for this check?
There was a problem hiding this comment.
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.
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.
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.
MylesBorins
commented
Mar 30, 2016
kevinoid
commented
Mar 30, 2016
Thanks @thealphanerd! |
mcollina
commented
Mar 30, 2016
Quite a few failures, we should probably have a closer look at them. |
mcollina
commented
Mar 30, 2016
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). |
kevinoid
commented
Mar 30, 2016
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 |
mcollina
commented
Mar 31, 2016
@kevinoid I'm not understanding all the various options you are laying out. Can you please clarify? I think we should emit/callback an |
kevinoid
commented
Mar 31, 2016
@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? |
mcollina
commented
Apr 1, 2016
I'm ok for option 2. Calvin? Il giorno gio 31 mar 2016 alle 20:19 Kevin Locke notifications@github.com
|
calvinmetcalf
commented
Apr 12, 2016
at the readable stream meeting yesterday we decide on 2 so I'll open a pull for that |
kevinoid
commented
Apr 12, 2016
Sounds good, thanks @calvinmetcalf! |
Here's a proposed fix for #5711, which passes
nullto._transform, like other falsey values.It updates the falsey value test for
Transformto includenull(andundefined, which was previously omitted) and adds a test for the falsey value behavior ofWritableinobjectMode, as requested in #5711 (comment)Let me know what you think @mcollina and @calvinmetcalf (and anyone else interested, of course).
Fixes: #5711