@@ -1478,6 +1478,8 @@ added: v10.0.0
1478
1478
** Default** : ` true ` .
1479
1479
* ` callback ` {Function} A callback function that takes an optional error
1480
1480
argument.
1481
+ * Returns: {Function} A cleanup function which removes all registered
1482
+ listeners.
1481
1483
1482
1484
A function to get notified when a stream is no longer readable, writable
1483
1485
or has experienced an error or a premature close event.
@@ -1518,6 +1520,20 @@ run().catch(console.error);
1518
1520
rs .resume (); // Drain the stream.
1519
1521
```
1520
1522
1523
+ ` stream.finished() ` leaves dangling event listeners (in particular
1524
+ ` 'error' ` , ` 'end' ` , ` 'finish' ` and ` 'close' ` ) after ` callback ` has been
1525
+ invoked. The reason for this is so that unexpected ` 'error' ` events (due to
1526
+ incorrect stream implementations) do not cause unexpected crashes.
1527
+ If this is unwanted behavior then the returned cleanup function needs to be
1528
+ invoked in the callback:
1529
+
1530
+ ``` js
1531
+ const cleanup = finished (... streams, (err ) => {
1532
+ cleanup ();
1533
+ // ...
1534
+ });
1535
+ ```
1536
+
1521
1537
### stream.pipeline(...streams, callback)
1522
1538
<!-- YAML
1523
1539
added: v10.0.0
@@ -1571,6 +1587,10 @@ async function run() {
1571
1587
run ().catch (console .error );
1572
1588
```
1573
1589
1590
+ ` stream.pipeline() ` leaves dangling event listeners on the streams
1591
+ after the ` callback ` has been invoked. In the case of reuse of streams after
1592
+ failure, this can cause event listener leaks and swallowed errors.
1593
+
1574
1594
### stream.Readable.from(iterable, [ options] )
1575
1595
<!-- YAML
1576
1596
added: v12.3.0
0 commit comments