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
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/webstreams/adapters.js +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -459,6 +459,7 @@ function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObj |
459 | 459 | const strategy = evaluateStrategyOrFallback(options?.strategy); |
460 | 460 |
|
461 | 461 | let controller; |
| 462 | + let wasCanceled = false; |
462 | 463 |
|
463 | 464 | function onData(chunk) { |
464 | 465 | // Copy the Buffer to detach it from the pool. |
@@ -480,6 +481,10 @@ function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObj |
480 | 481 | streamReadable.on('error', () => {}); |
481 | 482 | if (error) |
482 | 483 | return controller.error(error); |
| 484 | + // Was already canceled |
| 485 | + if (wasCanceled) { |
| 486 | + return; |
| 487 | + } |
483 | 488 | controller.close(); |
484 | 489 | }); |
485 | 490 |
|
@@ -491,6 +496,7 @@ function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObj |
491 | 496 | pull() { streamReadable.resume(); }, |
492 | 497 |
|
493 | 498 | cancel(reason) { |
| 499 | + wasCanceled = true; |
494 | 500 | destroy(streamReadable, reason); |
495 | 501 | }, |
496 | 502 | }, strategy); |
|
Collapse file
Copy file name to clipboard +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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
Copy file name to clipboard +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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 | +} |