Repository navigation
The 'error' event can be emitted more than once when using writable.destroy() #26015
Copy link
Copy link
Closed
Labels
streamIssues and PRs related to Node.js streams.Issues and PRs related to Node.js streams.
Description
Activity
- addedstreamIssues and PRs related to Node.js streams.Issues and PRs related to Node.js streams.
on Feb 9, 2019 This seems to fix the issue without breaking any existing tests
diff --git a/lib/internal/streams/destroy.js b/lib/internal/streams/destroy.js index 0c652be9dd..200c75459a 100644 --- a/lib/internal/streams/destroy.js +++ b/lib/internal/streams/destroy.js @@ -10,10 +10,15 @@ function destroy(err, cb) { if (readableDestroyed || writableDestroyed) { if (cb) { cb(err); - } else if (err && - (!this._writableState || !this._writableState.errorEmitted)) { - process.nextTick(emitErrorNT, this, err); + } else if (err) { + if (!this._writableState) { + process.nextTick(emitErrorNT, this, err); + } else if (!this._writableState.errorEmitted) { + this._writableState.errorEmitted = true; + process.nextTick(emitErrorNT, this, err); + } } + return this; } @@ -31,9 +36,13 @@ function destroy(err, cb) { this._destroy(err || null, (err) => { if (!cb && err) { - process.nextTick(emitErrorAndCloseNT, this, err); - if (this._writableState) { + if (!this._writableState) { + process.nextTick(emitErrorAndCloseNT, this, err); + } else if (!this._writableState.errorEmitted) { this._writableState.errorEmitted = true; + process.nextTick(emitErrorAndCloseNT, this, err); + } else { + process.nextTick(emitCloseNT, this); } } else if (cb) { process.nextTick(emitCloseNT, this);
but is there a reason for having no guard at all for readable only streams?
cc: @nodejs/streams
but is there a reason for having no guard at all for readable only streams?
The time needed for making it happen and dealing with the potential ecosystem breakage. If you got some stretch of time, send a PR!
@lpinca can you PR the changes in #26015 (comment)?
Yes, will do.
- added a commit that references this issue
on Feb 12, 2019 - added a commit that references this issue
on Mar 5, 2019 - added a commit that references this issue
on Mar 12, 2019 - added a commit that references this issue
on Apr 16, 2019 - added a commit that references this issue
on Jun 1, 2019 - added a commit that references this issue
on Sep 19, 2019
Metadata
Metadata
Assignees
Labels
streamIssues and PRs related to Node.js streams.Issues and PRs related to Node.js streams.
The
'error'event can be emitted multiple times when usingwritable.destroy()if the_destroy()callback is called asynchronously. Here is a test case:Actual result:
The
'error'event is emitted twice.Expected result:
The
'error'event is emitted only once.This is because the
_writableState.errorEmittedguard is set totruewhen the callback is called.