title: http.request timeout callback in Node.js
body: <p>currently I used the following code to handle the timeout:</p>
  
  <pre class="lang-js prettyprint-override"><code>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
   });
  </code></pre>
  
  <p>The problem is, when the remove server has a slow response and timeout, sometimes the timeout callback will be called, and sometimes <strong>both timeout callback and error callback will be called</strong> (the error inside the error callback is ECONNRESET - connection reset)</p>
  
  <p>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</p>