Node streams: a.pipe(b) does not destroy b when a errors, use stream/promises pipeline() instead
@aiden-f-dsouza▲ 7 net votes
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'.