Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.