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