mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	TCPGet: Ensure done() is called only once (#1068)
* Add additional safety checks to avoid acting on non-existent objects * TCPGet: yet more checks * TCPGet: seperate connected properties * TCPGet: properly handle node.done()
This commit is contained in:
		
				
					committed by
					
						 Dave Conway-Jones
						Dave Conway-Jones
					
				
			
			
				
	
			
			
			
						parent
						
							564902b886
						
					
				
				
					commit
					b530c1a43d
				
			| @@ -541,7 +541,19 @@ module.exports = function(RED) { | ||||
|                     if (clients[connection_id]) { | ||||
|                         clients[connection_id].connected  = false; | ||||
|                     } | ||||
|                     if (node.done) { node.done(); } | ||||
|  | ||||
|                     var anyConnected = false; | ||||
|  | ||||
|                     for (var client in clients) { | ||||
|                         if (clients[client].connected) { | ||||
|                             anyConnected = true; | ||||
|                             break; | ||||
|                         } | ||||
|                     } | ||||
|                     if (node.done && !anyConnected) { | ||||
|                         clients = {}; | ||||
|                         node.done(); | ||||
|                     } | ||||
|                 }); | ||||
|  | ||||
|                 clients[connection_id].client.on('error', function() { | ||||
| @@ -556,6 +568,7 @@ module.exports = function(RED) { | ||||
|                 }); | ||||
|  | ||||
|                 clients[connection_id].client.on('timeout',function() { | ||||
|                     //console.log("TIMEOUT"); | ||||
|                     clients[connection_id].connected = false; | ||||
|                     node.status({fill:"grey",shape:"dot",text:"tcpin.errors.connect-timeout"}); | ||||
|                     //node.warn(RED._("tcpin.errors.connect-timeout")); | ||||
| @@ -579,9 +592,20 @@ module.exports = function(RED) { | ||||
|             for (var client in clients) { | ||||
|                 clients[client].client.destroy(); | ||||
|             } | ||||
|             clients = {}; | ||||
|             node.status({}); | ||||
|             done(); | ||||
|  | ||||
|             var anyConnected = false; | ||||
|             for (var c in clients) { | ||||
|                 if (clients[c].connected) { | ||||
|                     anyConnected = true; | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             if (!anyConnected) { | ||||
|                 clients = {}; | ||||
|                 done(); | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user