GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — node:stream: no 'readable' behind 'end', and the cases of Node's test… · oven-sh/bun@dcddae2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/js/internal/streams
    • readable.ts
  • test/js/node
    • stream
      • node-stream.test.js
    • test/parallel
      • test-stream-readable-unobserved-eof-readable.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/js/internal/streams/readable.ts‎

Copy file name to clipboardExpand all lines: src/js/internal/streams/readable.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,8 @@ function endReadable(stream) {
16711671

16721672
$debug("endReadable");
16731673
if ((state[kState] & (kEndEmitted | kEndScheduled)) === 0) {
1674-
state[kState] |= kEnded | kEndScheduled;
1674+
// Not in Node: with 'end' queued, the 'readable' that a later listener is owed would come behind it.
1675+
state[kState] = (state[kState] | kEnded | kEndScheduled) & ~kEofReadablePending;
16751676
process.nextTick(endReadableNT, state, stream);
16761677
}
16771678
}
Collapse file

‎test/js/node/stream/node-stream.test.js‎

Copy file name to clipboardExpand all lines: test/js/node/stream/node-stream.test.js
+81-6Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,16 +1793,91 @@ describe("endReadable() queues one tick for 'end' (nodejs/node#65310)", () => {
17931793
});
17941794

17951795
describe("an EOF that nothing observes owes its 'readable' to a later listener (nodejs/node#65749)", () => {
1796-
it("read() takes the 'readable' that is owed", async () => {
1797-
// With autoDestroy, the stream is destroyed at 'end' and emits no 'readable' behind it in any case.
1798-
const r = new Readable({ read() {}, autoDestroy: false });
1796+
// Every tick of a stream runs before an immediate.
1797+
const immediate = () => new Promise(resolve => setImmediate(resolve));
1798+
function watch(r) {
1799+
const events = [];
1800+
r.on("readable", () => events.push(`readable ${r.read()}`));
1801+
r.on("end", () => events.push("end"));
1802+
return events;
1803+
}
1804+
1805+
// The five cases of test-stream-readable-unobserved-eof-readable.js, which Node.js v26.9.0 has.
1806+
it("a 'readable' listener in the tick of the EOF gets 'readable', then 'end'", async () => {
1807+
const r = new Readable({ read() {} });
1808+
r.push(null);
1809+
const events = watch(r);
1810+
await immediate();
1811+
expect(events).toEqual(["readable null", "end"]);
1812+
});
1813+
1814+
it("a 'readable' listener that comes an immediate later gets 'readable', then 'end'", async () => {
1815+
const r = new Readable({ read() {} });
1816+
r.push(null);
1817+
await immediate();
1818+
const events = watch(r);
1819+
await immediate();
1820+
expect(events).toEqual(["readable null", "end"]);
1821+
});
1822+
1823+
it("resume() an immediate later ends the stream", async () => {
1824+
const r = new Readable({ read() {} });
1825+
r.push(null);
1826+
await immediate();
1827+
const events = [];
1828+
r.on("end", () => events.push("end"));
1829+
r.resume();
1830+
await immediate();
1831+
expect(events).toEqual(["end"]);
1832+
});
1833+
1834+
it("read() an immediate later ends the stream", async () => {
1835+
const r = new Readable({ read() {} });
1836+
r.push(null);
1837+
await immediate();
1838+
const events = [`read ${r.read()}`];
1839+
r.on("end", () => events.push("end"));
1840+
await immediate();
1841+
expect(events).toEqual(["read null", "end"]);
1842+
});
1843+
1844+
it("a 'data' listener that comes an immediate later gets the chunk, then 'end'", async () => {
1845+
const r = new Readable({ read() {} });
1846+
r.push("x");
17991847
r.push(null);
1800-
expect(r.read()).toBe(null);
1848+
await immediate();
18011849
const events = [];
1850+
r.on("data", chunk => events.push(`data ${chunk}`));
1851+
r.on("end", () => events.push("end"));
1852+
await immediate();
1853+
expect(events).toEqual(["data x", "end"]);
1854+
});
1855+
1856+
// autoDestroy: false in the next two. A stream that 'end' destroyed emits no 'readable' in any case.
1857+
it("a read() that takes the last chunk takes the 'readable' that is owed", async () => {
1858+
const r = new Readable({ read() {}, autoDestroy: false });
1859+
r.push("x");
1860+
r.push(null);
1861+
const events = [`read ${r.read(1)}`];
18021862
r.on("readable", () => events.push("readable"));
18031863
r.on("end", () => events.push("end"));
1804-
// Every tick of the stream runs before an immediate.
1805-
await new Promise(resolve => setImmediate(resolve));
1864+
await immediate();
1865+
expect(events).toEqual(["read x", "end"]);
1866+
});
1867+
1868+
// Node.js v26.11.1 gives ["end", "readable"]: the read(0) of resume() queues 'end' and leaves the 'readable' owed.
1869+
it("no 'readable' comes behind 'end' after resume() and pause()", async () => {
1870+
const r = new Readable({ read() {}, autoDestroy: false });
1871+
r.push(null);
1872+
r.resume();
1873+
r.pause();
1874+
const events = [];
1875+
// This tick is behind the one of resume(), which queues 'end', and before the one of 'end'.
1876+
process.nextTick(() => {
1877+
r.on("readable", () => events.push("readable"));
1878+
r.on("end", () => events.push("end"));
1879+
});
1880+
await immediate();
18061881
expect(events).toEqual(["end"]);
18071882
});
18081883
});
Collapse file

‎test/js/node/test/parallel/test-stream-readable-unobserved-eof-readable.js‎

Copy file name to clipboardExpand all lines: test/js/node/test/parallel/test-stream-readable-unobserved-eof-readable.js
-76Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.