http-request icon indicating copy to clipboard operation
http-request copied to clipboard

http.get running twice on timeout

Open kerloom opened this issue 7 years ago • 2 comments

Using async.auto I am running an http.get() with timeout. After the timeout error, http.get is ran again causing a Callback is already called error. I am getting this error because http.get is ran twice, one time after the timeout.

kerloom avatar Feb 16 '18 20:02 kerloom

An code example proving the issue is always welcome.

SaltwaterC avatar Feb 17 '18 22:02 SaltwaterC

Sorry for the delay. This codes replicates the error, just change the URL to an unresponsive to generate the timeout, or set the timeout really low.

var async = require('async'),
    http = require('http-get'),
    URL = "unresponsive-url.com";

console.log("Starting");
async.auto({
    one: function(callback) {
        console.log("Running http-get");
        http.get(
          {
            timeout: 5000,
            url: URL
          },
          function(err, res) {
            console.log("Running http-get callback");
            if(err){
                console.log("error");
            }
            else {
                console.log("OK");
            }
            callback(callback);
          }
        );
    },
    two: ['one',
        function (callback) {
            console.log("Running two");
            callback(callback);
        }
    ]
}, function(err, results) {
    console.log("Running callback.");
});

kerloom avatar Feb 19 '18 18:02 kerloom