@@ -1478,6 +1478,8 @@ added: v10.0.0
14781478 ** Default** : ` true ` .
14791479* ` callback ` {Function} A callback function that takes an optional error
14801480 argument.
1481+ * Returns: {Function} A cleanup function which removes all registered
1482+ listeners.
14811483
14821484A function to get notified when a stream is no longer readable, writable
14831485or has experienced an error or a premature close event.
@@ -1518,6 +1520,20 @@ run().catch(console.error);
15181520rs .resume (); // Drain the stream.
15191521```
15201522
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+
15211537### stream.pipeline(...streams, callback)
15221538<!-- YAML
15231539added: v10.0.0
@@ -1571,6 +1587,10 @@ async function run() {
15711587run ().catch (console .error );
15721588```
15731589
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+
15741594### stream.Readable.from(iterable, [ options] )
15751595<!-- YAML
15761596added: v12.3.0
0 commit comments