Permalink
Browse files

Close HTTP socket properly in event of timeout

  • Loading branch information...
1 parent f1eba40 commit 5a30f30e4844fbd4b33c47fa5aa5b591f1e67834 Loren Segal committed Mar 15, 2013
Showing with 8 additions and 2 deletions.
  1. +8 −2 lib/http.js
View
@@ -187,9 +187,15 @@ AWS.NodeHttpClient = inherit({
stream.setTimeout(httpOptions.timeout || 0);
stream.on('timeout', function() {
var msg = 'Connection timed out after ' + httpOptions.timeout + 'ms';
- stream.end();
errCallback(AWS.util.error(new Error(msg), {code: 'TimeoutError'}));
- })
+
+ // HACK - abort the connection without tripping our error handler
+ // since we already raised our TimeoutError. Otherwise the connection
+ // comes back with ECONNRESET, which is not a helpful error message
+ stream.removeListener('error', errCallback);
+ stream.on('error', function() { });
+ stream.abort();
+ });
stream.on('error', errCallback);
this.writeBody(stream, httpRequest);

0 comments on commit 5a30f30

Please sign in to comment.