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 — stream: fix ERR_INVALID_STATE when cancelling Readable.toWeb() · nodejs/node@1278496

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/webstreams
    • adapters.js
  • test/parallel
    • test-stream-readable-to-web-termination.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/webstreams/adapters.js‎

Copy file name to clipboardExpand all lines: lib/internal/webstreams/adapters.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObj
613613
streamReadable.pause();
614614

615615
streamReadable.on('data', function onData(chunk) {
616+
if (wasCanceled) return;
616617
// Copy the Buffer to detach it from the pool.
617618
if (Buffer.isBuffer(chunk) && !objectMode)
618619
chunk = new Uint8Array(chunk);
Collapse file

‎test/parallel/test-stream-readable-to-web-termination.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-readable-to-web-termination.js
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,25 @@ const { setTimeout: delay } = require('timers/promises');
4242
assert.deepStrictEqual(closeResult, { value: undefined, done: true });
4343
})().then(common.mustCall());
4444
}
45+
46+
// Cancelling a web ReadableStream while the underlying Readable is actively
47+
// producing data should not throw ERR_INVALID_STATE. The 'data' handler in
48+
// newReadableStreamFromStreamReadable must check wasCanceled before calling
49+
// controller.enqueue(). See: https://github.com/nodejs/node/issues/54205
50+
{
51+
const readable = new Readable({
52+
read() {
53+
this.push(Buffer.alloc(1024));
54+
},
55+
});
56+
57+
const webStream = Readable.toWeb(readable);
58+
const reader = webStream.getReader();
59+
60+
(async () => {
61+
await reader.read();
62+
await reader.read();
63+
reader.releaseLock();
64+
await webStream.cancel();
65+
})().then(common.mustCall());
66+
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — 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.