From dcb8ed2dca3129aaac64c99d9bc694ef7f713e2f Mon Sep 17 00:00:00 2001 From: hub_Prateek Date: Fri, 14 Jul 2023 21:48:46 +0530 Subject: [PATCH] Check added for destroyed stream in onwrite function --- lib/internal/streams/writable.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/internal/streams/writable.js b/lib/internal/streams/writable.js index 718d4e48478677..10ebe71b1668a2 100644 --- a/lib/internal/streams/writable.js +++ b/lib/internal/streams/writable.js @@ -292,7 +292,7 @@ Writable.prototype.pipe = function() { function _write(stream, chunk, encoding, cb) { const state = stream._writableState; - + if (typeof encoding === 'function') { cb = encoding; encoding = state.defaultEncoding; @@ -436,7 +436,11 @@ function onwrite(stream, er) { const state = stream._writableState; const sync = state.sync; const cb = state.writecb; - + + if(state.destroyed){ + throw new ERR_STREAM_DESTROYED('write'); + return; + } if (typeof cb !== 'function') { errorOrDestroy(stream, new ERR_MULTIPLE_CALLBACK()); return;