nodejs / nodejs/node

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

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

Nobody has claimed this yet.

stale
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

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)
}

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.

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.