Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

http: Remove socket from agent on error

Potential fix for #3236
  • Loading branch information...
commit 9d3bd8a239862ee9293a7af9785856f8abdab096 1 parent bf9d8e9
@isaacs authored
Showing with 13 additions and 0 deletions.
  1. +13 −0 lib/http.js
View
13 lib/http.js
@@ -969,6 +969,18 @@ Agent.prototype.createSocket = function(name, host, port) {
self.removeSocket(s, name, host, port);
}
s.on('close', onClose);
+
+ var onError = function(er) {
+ if (this._httpMessage) {
+ this._httpMessage.emit('error', er);
+ } else {
+ // This socket is broken, but we don't actually care about it
+ // at the time. Just throw it away as if the socket had closed.
+ onClose();
+ }
+ };
+ s.on('error', onError);
+
var onRemove = function() {
// We need this function for cases like HTTP "upgrade"
// (defined by WebSockets) where we need to remove a socket from the pool
@@ -977,6 +989,7 @@ Agent.prototype.createSocket = function(name, host, port) {
s.removeListener('close', onClose);
s.removeListener('free', onFree);
s.removeListener('agentRemove', onRemove);
+ s.removeListener('error', onError);
}
s.on('agentRemove', onRemove);
return s;
Please sign in to comment.
Something went wrong with that request. Please try again.