summaryrefslogtreecommitdiff
path: root/lib/_stream_writable.js
diff options
context:
space:
mode:
authorRobert Nagy <ronagy@icloud.com>2019-08-06 22:16:05 +0200
committerRich Trott <rtrott@gmail.com>2019-09-22 16:25:50 -0700
commitaa32e13968a00ee4dccea4cf9aa388a6ff613d89 (patch)
tree35812424b918ed95529e4ae91a8c1e98fd85fc90 /lib/_stream_writable.js
parent95d6ad67bfc9ef3e2f4705c81c88e32c5b1cea51 (diff)
downloadandroid-node-v8-aa32e13968a00ee4dccea4cf9aa388a6ff613d89.tar.gz
android-node-v8-aa32e13968a00ee4dccea4cf9aa388a6ff613d89.tar.bz2
android-node-v8-aa32e13968a00ee4dccea4cf9aa388a6ff613d89.zip
stream: do not flush destroyed writable
It doesn't make much sense to flush a stream which has been destroyed. PR-URL: https://github.com/nodejs/node/pull/29028 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'lib/_stream_writable.js')
-rw-r--r--lib/_stream_writable.js24
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js
index 185407cfd8..41114f41bb 100644
--- a/lib/_stream_writable.js
+++ b/lib/_stream_writable.js
@@ -299,9 +299,13 @@ Writable.prototype.write = function(chunk, encoding, cb) {
if (typeof cb !== 'function')
cb = nop;
- if (state.ending)
+ if (state.ending) {
writeAfterEnd(this, cb);
- else if (isBuf || validChunk(this, state, chunk, cb)) {
+ } else if (state.destroyed) {
+ const err = new ERR_STREAM_DESTROYED('write');
+ process.nextTick(cb, err);
+ errorOrDestroy(this, err);
+ } else if (isBuf || validChunk(this, state, chunk, cb)) {
state.pendingcb++;
ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
}
@@ -733,7 +737,21 @@ Object.defineProperty(Writable.prototype, 'writableFinished', {
}
});
-Writable.prototype.destroy = destroyImpl.destroy;
+const destroy = destroyImpl.destroy;
+Writable.prototype.destroy = function(err, cb) {
+ const state = this._writableState;
+ if (!state.destroyed) {
+ for (let entry = state.bufferedRequest; entry; entry = entry.next) {
+ process.nextTick(entry.callback, new ERR_STREAM_DESTROYED('write'));
+ }
+ state.bufferedRequest = null;
+ state.lastBufferedRequest = null;
+ state.bufferedRequestCount = 0;
+ }
+ destroy.call(this, err, cb);
+ return this;
+};
+
Writable.prototype._undestroy = destroyImpl.undestroy;
Writable.prototype._destroy = function(err, cb) {
cb(err);