in transform stream transform method, `callback(null, null)` doesn't end stream but `this.push(null); callback()` does

Closed Beginner friendly
#62,769 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
javascript

Research direction

Start in lib/internal/streams/transform.js at lines 177-179 and compare the documented Transform callback behavior with the existing stream implementation. Reproduce the difference between callback(null, null) and this.push(null); callback(), then inspect the relevant stream tests. Done means both forms consistently end the stream as described.

Written by the indexing model from the issue text.

Description

stale
Version

latest main branch

Platform
irrelevant
Subsystem

stream

What steps will reproduce the bug?

https://nodejs.org/api/stream.html#transform-transformchunk-encoding-callback

callback(null, null) doesn't end stream but this.push(null); callback() does

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

callback(null, null) and this.push(null); callback() have the same effect (the stream ends).

What do you see instead?

callback(null, null) is different from this.push(null); callback()

Additional information

https://github.com/nodejs/node/blob/main/lib/internal/streams/transform.js#L177-L179

Would it be possible to change this to the following?

if (val !== undefined) {
  this.push(val)
}
Dominant language
JavaScript
Stars
122k
Forks
37.4k
Avg merge
4d 4h
Merged PRs (30d)
276

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nodejs/node

All issues in nodejs/node

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.