-
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: Writing null to objectMode Transform is unrecoverable #5711
Comments
@nodejs/streams |
maybe have _write do process.nextTick(cb) if chunk === null ? |
I'm not sure what is the proper fix, but give it a go, add at least one unit test covering this issue, and what is your best fix. Just to clarify, what does it happen if you write null to a Writable? I agree we need to fix this. |
@calvinmetcalf Sure, that would work. Is there a reason why you'd discard the write, rather than pass it to @mcollina Will do. Calling |
@kevinoid add a unit test also for @calvinmetcalf I think the best behavior is to move around all falsey values as they are. cc @mafintosh :) |
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
I think this has been resolved by #6170, if I’m mistaken feel free to re-open. |
If
null
is written to an instance ofstream.Transform
, the stream does not complete additional writes, emit additional data, nor emit an'error'
or'end'
event. As an example, consider the following:This prints
Instead of write2 either causing an error or being ignored and write3 completing normally followed by
'end'
.This occurs because
null
writechunk
skips._transform
without callingts.writecb
causingWritable
to buffer subsequent writes waiting for._write(null, ...)
to complete. This behavior has been present since 26ca7d7.If there is agreement on the appropriate behavior, I can work up a PR. I would suggest removing the
ts.writechunk !== null
check so that the value will be passed to._transform
to match the current handling ofundefined
. If_.transform
returns it unchanged, it would be ignored, likeundefined
. Discarding the write, with or without error, could be reasonable as well.Thanks for considering,
Kevin
The text was updated successfully, but these errors were encountered: