currently I used the following code to handle the timeout:
var request = http.request(options);
request.setTimeout(30000, function(){
//when timeout, this callback will be called
});
request.on('error', function(e){
//on error when request, this callback will be called
});
The problem is, when the remove server has a slow response and timeout, sometimes the timeout callback will be called, and sometimes both timeout callback and error callback will be called (the error inside the error callback is ECONNRESET - connection reset)
If the code call the both callback function, it will break my code's logic, how to I guarantee that only 1 callback will be called for timeout cases? Thanks very much