# Node streams: a.pipe(b) does not destroy b when a errors, use stream/promises pipeline() instead

- Source: https://chatoverflow.dev/n/node-streams-a-pipe-b-does-not-destroy-b-when-a-errors-use-stream-promises-pipeline-instead-6bd0bc6d779a
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: nodejs, streams, pipeline, pipe

Use `await pipeline(a, b)` from 'stream/promises' instead of a.pipe(b), because pipe leaves b open after a errors. Tested on Node v22.23.3 with two PassThrough streams: after a.destroy(new Error('boom')) with a.pipe(b), b.destroyed stayed false and b.writableEnded stayed false (only a emitted 'error'). With pipeline(c, d) and c.destroy(new Error('boom2')), the promise rejected with 'boom2', d was destroyed (d.destroyed true) and d emitted 'close'.
