fix: guard against late chunk after consume teardown#5357
Open
cesarvspr wants to merge 1 commit into
Open
Conversation
`consumeFinish` sets `consume.body = null` on teardown (close/abort/error) but leaves `stream[kConsume]` in place. A chunk arriving afterwards - for example flushed by a decompress interceptor - reached `consumePush` and crashed synchronously with "Cannot read properties of null (reading 'push')" instead of being dropped. Add a null guard in `consumePush`, consistent with the existing guards in `consumeStart` and the 'close' handler, so late chunks are dropped and the consume promise still rejects with the expected AbortError. Fixes: nodejs#5356 Signed-off-by: cesarvspr <vinicius_spr@hotmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5357 +/- ##
=======================================
Coverage 93.23% 93.24%
=======================================
Files 110 110
Lines 36668 36676 +8
=======================================
+ Hits 34189 34197 +8
Misses 2479 2479 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
metcoder95
approved these changes
Jun 4, 2026
mcollina
requested changes
Jun 5, 2026
Member
mcollina
left a comment
There was a problem hiding this comment.
I think the bug is elsewhere. That function should not be called.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This relates to...
Fixes #5356
Rationale
When a body is consumed (
body.json()/text()/etc.) and the stream is then torn down (close/abort/timeout/error),consumeFinishsetsconsume.body = nullbut leavesstream[kConsume]in place. If a chunk arrives afterwards — e.g. flushed by a decompress interceptor after teardown —pushstill routes it toconsumePush, which didconsume.body.push(chunk)onnulland crashed synchronously with:instead of dropping the late chunk and letting the consume promise reject normally.
The same teardown race is already guarded in two sibling code paths —
consumeStart(if (consume.body === null) return) and the'close'handler (if (this[kConsume].body !== null)).consumePushwas simply missing the equivalent guard. This parallels the HTTP/2 teardown guards added in #4880.Changes
lib/api/readable.js: add aconsume.body === nullguard at the top ofconsumePushso late chunks are dropped instead of crashing.Features
N/A
Bug Fixes
.json()/.text()reject withUND_ERR_ABORTEDas expected.Breaking Changes and Deprecations
N/A
Status
Test
Added a regression test in
test/readable.js(late chunk after consume teardown does not crash). It fails onmainwith the null-deref and passes with the fix:node --test test/readable.js→ 10/10 passing;npm run lintclean.