From 9d811c7bce3a0e6a0aa0590ae1313881d0dc6639 Mon Sep 17 00:00:00 2001 From: Debadutta Panda Date: Sat, 8 Feb 2025 11:13:04 +0530 Subject: [PATCH] Improve clone stream handling by adding safety checks for writable and destroyed states --- .../@node-red/nodes/core/network/21-httpin.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/network/21-httpin.js b/packages/node_modules/@node-red/nodes/core/network/21-httpin.js index 4d7786838..e8f99d2dc 100644 --- a/packages/node_modules/@node-red/nodes/core/network/21-httpin.js +++ b/packages/node_modules/@node-red/nodes/core/network/21-httpin.js @@ -119,8 +119,8 @@ module.exports = function(RED) { // Function to handle 'data' event function onData(chunk) { - // Continue pushing chunks into clone stream if it is writable. - if (!cloneStream.writable) { + // Safely call clone stream write + if (cloneStream.writable) { cloneStream.write(chunk); } } @@ -128,12 +128,15 @@ module.exports = function(RED) { // Function to handle 'end' or 'error' events function onEnd(err) { if (err) { - // If clone stream is already destroyed don't call destory function again + // Safely call clone stream destroy method if (!cloneStream.destroyed) { cloneStream.destroy(err); } } else { - cloneStream.end(); + // Safely call clone stream end method + if(cloneStream.writable) { + cloneStream.end(); + } } }