mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Improve clone stream handling by adding safety checks for writable and destroyed states
This commit is contained in:
		@@ -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();
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user