From 65dc6ee04a3fa4d526bba68975a735265ae2f2da Mon Sep 17 00:00:00 2001 From: Andrey Bezugliy Date: Thu, 2 May 2019 13:38:56 +0300 Subject: [PATCH] Close and destroy sockets on connection error. Add `sock.end` and `sock.destroy` calls for `sock.once('error', ...)` event handler and for `c.open(fields, ...)` callback - just like it was done for connection timeout callback. Resolves #513 --- lib/connect.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/connect.js b/lib/connect.js index 603f1981..23af26db 100644 --- a/lib/connect.js +++ b/lib/connect.js @@ -151,7 +151,11 @@ function connect(url, socketOptions, openCallback) { if (err === null) { openCallback(null, c); } - else openCallback(err); + else { + sock.end(); + sock.destroy(); + openCallback(err); + } }); } @@ -174,7 +178,11 @@ function connect(url, socketOptions, openCallback) { } sock.once('error', function(err) { - if (!sockok) openCallback(err); + if (!sockok) { + sock.end(); + sock.destroy(); + openCallback(err); + } }); }