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 — lib: fix unhandled errors in webstream adapters · nodejs/node@783322f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/webstreams
    • adapters.js
  • test/parallel
    • test-stream-readable-from-web-termination.js
    • 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
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObj
459459
const strategy = evaluateStrategyOrFallback(options?.strategy);
460460

461461
let controller;
462+
let wasCanceled = false;
462463

463464
function onData(chunk) {
464465
// Copy the Buffer to detach it from the pool.
@@ -480,6 +481,10 @@ function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObj
480481
streamReadable.on('error', () => {});
481482
if (error)
482483
return controller.error(error);
484+
// Was already canceled
485+
if (wasCanceled) {
486+
return;
487+
}
483488
controller.close();
484489
});
485490

@@ -491,6 +496,7 @@ function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObj
491496
pull() { streamReadable.resume(); },
492497

493498
cancel(reason) {
499+
wasCanceled = true;
494500
destroy(streamReadable, reason);
495501
},
496502
}, strategy);
Collapse file

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

Copy file name to clipboard
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
require('../common');
3+
const { Readable } = require('stream');
4+
5+
{
6+
const r = Readable.from(['data']);
7+
8+
const wrapper = Readable.fromWeb(Readable.toWeb(r));
9+
10+
wrapper.on('data', () => {
11+
// Destroying wrapper while emitting data should not cause uncaught
12+
// exceptions
13+
wrapper.destroy();
14+
});
15+
}
Collapse file

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

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
require('../common');
3+
const { Readable } = require('stream');
4+
5+
{
6+
const r = Readable.from([]);
7+
// Cancelling reader while closing should not cause uncaught exceptions
8+
r.on('close', () => reader.cancel());
9+
10+
const reader = Readable.toWeb(r).getReader();
11+
reader.read();
12+
}

0 commit comments

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