Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created May 9, 2012 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/2640942 to your computer and use it in GitHub Desktop.
Save isaacs/2640942 to your computer and use it in GitHub Desktop.
diff --git a/lib/http.js b/lib/http.js
index 070942e..999e0e6 100644
--- a/lib/http.js
+++ b/lib/http.js
@@ -969,6 +969,14 @@ 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 if (this.listeners('error').length === 1) {
+ throw er;
+ }
+ };
+ 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 +985,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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment