From b3c1d6b9c551b8fd485937d683304d199885c7a9 Mon Sep 17 00:00:00 2001 From: manish Date: Thu, 18 Sep 2014 14:18:55 +0530 Subject: [PATCH 1/2] timer should be cleared when request completes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit clear the timer when ‘end’ event is received on the response. --- lib/requestify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/requestify.js b/lib/requestify.js index 9293f1b..cf5b755 100644 --- a/lib/requestify.js +++ b/lib/requestify.js @@ -94,7 +94,6 @@ var Requestify = (function() { * Handle request callback */ httpRequest = http.request(options, function(res) { - clearTimeout(timeout); var response = new Response(res.statusCode, res.headers); res.setEncoding(responseEncoding); @@ -103,6 +102,7 @@ var Requestify = (function() { }); res.on('end', function() { + clearTimeout(timeout); if (isSuccessful(response.code)) { storeCache(request.getFullUrl(), response.getCode(), response.getHeaders(), response.body, request.cache); defer.resolve(response); From 36791aa39b5a82eae83ce1e0173851f92b74121a Mon Sep 17 00:00:00 2001 From: manish Date: Tue, 27 Oct 2015 13:17:03 +0530 Subject: [PATCH 2/2] in case of error, the timer should be cleared the timer created not cleared up in case of an error event. --- lib/requestify.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/requestify.js b/lib/requestify.js index cf5b755..d93995d 100644 --- a/lib/requestify.js +++ b/lib/requestify.js @@ -125,6 +125,7 @@ var Requestify = (function() { * Reject on error and pass the given error object */ httpRequest.on('error', function(error) { + clearTimeout(timeout); defer.reject(error); });