Skip to content

Commit

Permalink
http: Remove socket from agent on error
Browse files Browse the repository at this point in the history
Potential fix for nodejs#3236
  • Loading branch information
isaacs committed May 9, 2012
1 parent bf9d8e9 commit 9d3bd8a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 9d3bd8a

Please sign in to comment.