diff options
author | Mathias Buus <mathiasbuus@gmail.com> | 2018-04-05 20:52:19 +0200 |
---|---|---|
committer | Mathias Buus <mathiasbuus@gmail.com> | 2018-04-09 12:30:41 +0200 |
commit | a7c25b7d42b79878548b9d660af0195e7318fc33 (patch) | |
tree | 2b1b1b81f2a63c33dcdee6a1ac513aaa24af25b3 /lib | |
parent | 0cd8359652b39cdb577ac3c67bdea03e6aba9f97 (diff) | |
download | android-node-v8-a7c25b7d42b79878548b9d660af0195e7318fc33.tar.gz android-node-v8-a7c25b7d42b79878548b9d660af0195e7318fc33.tar.bz2 android-node-v8-a7c25b7d42b79878548b9d660af0195e7318fc33.zip |
stream: always emit error before close
PR-URL: https://github.com/nodejs/node/pull/19836
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/streams/destroy.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/internal/streams/destroy.js b/lib/internal/streams/destroy.js index 5d29e18204..3a0383cc3c 100644 --- a/lib/internal/streams/destroy.js +++ b/lib/internal/streams/destroy.js @@ -30,20 +30,27 @@ function destroy(err, cb) { } this._destroy(err || null, (err) => { - process.nextTick(emitCloseNT, this); if (!cb && err) { - process.nextTick(emitErrorNT, this, err); + process.nextTick(emitErrorAndCloseNT, this, err); if (this._writableState) { this._writableState.errorEmitted = true; } } else if (cb) { + process.nextTick(emitCloseNT, this); cb(err); + } else { + process.nextTick(emitCloseNT, this); } }); return this; } +function emitErrorAndCloseNT(self, err) { + emitErrorNT(self, err); + emitCloseNT(self); +} + function emitCloseNT(self) { if (self._writableState && !self._writableState.emitClose) return; |