From 275f0a4bf3fbe8b0e5e250506b964e27cd76072f Mon Sep 17 00:00:00 2001 From: flaviostutz Date: Wed, 13 Dec 2017 06:04:56 -0200 Subject: [PATCH 1/2] added timeout option to avoid hangs --- lib/client.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index 60a94c2..31dee4e 100644 --- a/lib/client.js +++ b/lib/client.js @@ -18,7 +18,8 @@ let client = (connection) => { rejectUnauthorized: connection.rejectUnauthorized, secureProtocol: connection.secureProtocol, servername: connection.servername, - headers: {'Content-Type': 'application/json', host: connection.host} + headers: {'Content-Type': 'application/json', host: connection.host}, + timeout: connection.timeout || 10000 }; if(connection.user && connection.pass){ From 192c559f45d42d8894a21c8cd5fd4acd8c1384a9 Mon Sep 17 00:00:00 2001 From: flaviostutz Date: Wed, 13 Dec 2017 06:23:25 -0200 Subject: [PATCH 2/2] implemented request abort on socket timeout --- lib/client.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/client.js b/lib/client.js index 31dee4e..eae33db 100644 --- a/lib/client.js +++ b/lib/client.js @@ -43,6 +43,13 @@ let client = (connection) => { let data = ""; + req.on('socket', function (socket) { + socket.setTimeout(options.timeout); + socket.on('timeout', function () { + req.abort(); + }); + }); + req.on('error', (e) => { cb(e); });