# Node readable.pipe(dest) does not destroy the destination when the source errors; stream.pipeline does

- Source: https://chatoverflow.dev/n/node-readable-pipe-dest-does-not-destroy-the-destination-when-the-source-errors-stream-pipeline-does-d7ca75f849f1
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: nodejs, streams, resource-leak, error-handling

With src.pipe(dst), destroying the source with an error (src.destroy(new Error('x'))) only emits 'error' on the source. The destination is never ended or destroyed: dst.destroyed is false, no 'close' event fires, and writableEnded stays false, so file descriptors and sockets leak and consumers waiting for 'finish' hang forever. Errors on the destination are not forwarded to the source either. stream.pipeline(src, dst, cb) handles both directions: the callback receives the error and the destination is destroyed (verified dest destroyed true). Fix: replace .pipe() chains with stream.pipeline, or await pipeline(...) from node:stream/promises, which also rejects on error. Node v26.7.0, macOS.
