From 4a2bd69db99c1bb8692e1f653edcb225fbc23032 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Tue, 16 Jul 2019 00:03:23 +0200 Subject: [PATCH] stream: fix destroy() behavior Ensure errorEmitted is always set. Only emit 'error' once. PR-URL: https://github.com/nodejs/node/pull/29058 Reviewed-By: Matteo Collina Reviewed-By: Luigi Pinca Reviewed-By: Franziska Hinkelmann Reviewed-By: Rich Trott --- doc/api/stream.md | 3 + lib/_stream_readable.js | 3 + lib/_stream_writable.js | 2 - lib/internal/streams/destroy.js | 107 ++++++++++-------- test/parallel/test-net-connect-buffer.js | 6 +- test/parallel/test-stream-error-once.js | 19 ++++ .../test-stream-readable-invalid-chunk.js | 33 ++++-- test/parallel/test-stream-readable-unshift.js | 17 --- .../parallel/test-stream-unshift-read-race.js | 8 +- test/parallel/test-stream2-writable.js | 39 +++++++ 10 files changed, 153 insertions(+), 84 deletions(-) create mode 100644 test/parallel/test-stream-error-once.js diff --git a/doc/api/stream.md b/doc/api/stream.md index cb6d23e52583ec..07755e05dc2f65 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -281,6 +281,9 @@ The stream is not closed when the `'error'` event is emitted unless the [`autoDestroy`][writable-new] option was set to `true` when creating the stream. +After `'error'`, no further events other than `'close'` *should* be emitted +(including `'error'` events). + ##### Event: 'finish'