Skip to content

doc: clarify readable._read() and pipe() error behavior#62196

Open
kovan wants to merge 1 commit intonodejs:mainfrom
kovan:doc-stream-read-pipe
Open

doc: clarify readable._read() and pipe() error behavior#62196
kovan wants to merge 1 commit intonodejs:mainfrom
kovan:doc-stream-read-pipe

Conversation

@kovan
Copy link

@kovan kovan commented Mar 11, 2026

Summary

All changes verified against lib/internal/streams/readable.js:

  • kReading flag is set before _read() (line 740), cleared in push()
    (line 506); maybeReadMore_ loops while kReading is unset (line 896)
  • pipe() only attaches an 'error' listener on dest (line 1047), not
    on src

Fixes: #42291
Fixes: #45072
Fixes: #46908

- Rewrite readable._read() description to resolve contradictory
  statements about when _read() is called relative to push(). The new
  text clarifies that: push() may be called multiple times until it
  returns false; _read() will not be called again until push() provides
  non-empty data; and if data is not immediately available, push()
  should be called asynchronously when data arrives.

- Clarify pipe() error caveat to specify that when the source stream is
  destroyed or emits an error, the destination is not closed
  automatically. Recommend stream.pipeline() for automatic cleanup.

Verified against source:
- lib/internal/streams/readable.js: kReading flag set before _read(),
  cleared in push(); maybeReadMore_ loops while kReading is unset
- pipe() only listens for 'error' on destination, not on source

Fixes: nodejs#42291
Fixes: nodejs#45072
Fixes: nodejs#46908

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. stream Issues and PRs related to the stream subsystem. labels Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Issues and PRs related to the documentations. stream Issues and PRs related to the stream subsystem.

Projects

None yet

2 participants