Repository navigation
Description
Version
v26.11.0, v26.12.1, v26.13.1 (works in v26.10.0 and in v20, v22 and v24)
Platform
Linux 192.168.1.15 5.14.0-687.15.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jun 11 16:33:25 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
(It must be noted this is the Hosts' command. The replication is done inside a Podman Container)
Subsystem
stream
What steps will reproduce the bug?
'use strict';
const { Readable, Writable } = require('node:stream');
// Source pushes EOF in a later _read() call than its last chunk.
const chunks = [Buffer.alloc(64), Buffer.alloc(64), Buffer.alloc(64)];
let i = 0;
const src = new Readable({
highWaterMark: 64,
read() { this.push(i < chunks.length ? chunks[i++] : null); },
});
// Destination completes every write except the last one.
let n = 0;
const dest = new Writable({
highWaterMark: 1,
write(chunk, enc, cb) { if (++n < chunks.length) setImmediate(cb); },
});
let endCalled = false;
const end = dest.end;
dest.end = function(...args) { endCalled = true; return end.apply(this, args); };
src.pipe(dest);
setTimeout(() => {
console.log(`${process.version}: src 'end' emitted: ${src.readableEnded}, dest.end() called: ${endCalled}`);
}, 100);How often does it reproduce? Is there a required condition?
Always, when both of these hold:
- the source pushes
nullin a_read()call after the one that pushed its last chunk, and dest.write()returnsfalsefor that last chunk.
What is the expected behavior? Why is that the expected behavior?
v26.10.0: src 'end' emitted: true, dest.end() called: true
This is the behavior of v26.10.0 and earlier, including v20, v22 and v24. There, read() schedules endReadable() once it has hit EOF and the buffer is empty, so pipe() calls dest.end() without waiting for 'drain'.
What do you see instead?
v26.11.0: src 'end' emitted: false, dest.end() called: false
v26.13.1: src 'end' emitted: false, dest.end() called: false
The source stays paused with readableEnded === false and _readableState.ended === true. 'end' is only emitted if the destination emits another 'drain'.
Additional information
Additional information
Bisected across the published binaries: v26.10.0 is good and v26.11.0 is bad. The relevant change is the new flowSync() fast path in lib/internal/streams/readable.js. When _read() pushes EOF while flowSync() is delivering the last chunk, nothing schedules endReadable(), whereas the general read() path does (if (nOrig !== n && (state[kState] & kEnded) !== 0) endReadable(this);).
Real-world impact: @azure/storage-blob's BuffersStream has exactly this shape, and node-fetch 2.x sends request bodies with body.pipe(req). Since v26.11.0, uploads through that stack (for example actions/upload-artifact-style clients) can leave a request that never calls req.end(). Combined with #YYYYY (the HTTP client drops the socket 'drain' once the response is complete), the upload step finishes its work and the process then never exits. We saw this in CI over HTTPS, in about 7 of 8 runs uploading a ~180 MB artifact in 8 MiB blocks.
AI Disclaimer
This report was made almost entirely with an AI. With the exception of this precise disclaimer.
In particular, this was a bug I found in production for our local infrastructure, where CI runs in a self-hosted Forgejo, and a Forgejo Runner, suddenly hung when using forgejo/upload-artifacts@v4 and @v5 with a ~200MB artifact, despite everything working with @V3, and in earlier versions of node.
For now we are reverting to @V3, but I am obviously notifying the maintainers of the forgejo runner so this can be worked around upstream.
The AI agent has made a patch that schedules endReadable() in flowSync() under the same condition as read(), with a test.
I don't post a PR, because the AI contribution guidelines specify that the user proposing a PR must fully understand the changes, which I don't yet fully. Thus I post the patch and other relevant files, so the maintainers can check its accuracy, and maybe implement their own patch/test if needed
I am open to any other data that might be needed to clarify the situation, to the best of my ability.
Found at the same time as issue #67763
0001-stream-emit-end-after-backpressured-last-pipe-chunk.patch
Activity
AZMCode commentedon Nov 25, 2026
Given the developments in the PR thread, this should probably be closed.