From e2400f88d85f67fb241a30f8f527f60f464bc04c Mon Sep 17 00:00:00 2001 From: isaacs Date: Sat, 9 Mar 2013 18:46:39 -0800 Subject: http: Do not setTimeout a not-yet-existent socket Fixes #4967 --- lib/http.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/http.js') diff --git a/lib/http.js b/lib/http.js index 1f52d31514..2f4bcc51e2 100644 --- a/lib/http.js +++ b/lib/http.js @@ -445,6 +445,9 @@ function OutgoingMessage() { this.finished = false; this._hangupClose = false; + + this.socket = null; + this.connection = null; } util.inherits(OutgoingMessage, Stream); @@ -455,7 +458,12 @@ exports.OutgoingMessage = OutgoingMessage; OutgoingMessage.prototype.setTimeout = function(msecs, callback) { if (callback) this.on('timeout', callback); - this.socket.setTimeout(msecs); + if (!this.socket) { + this.once('socket', function(socket) { + socket.setTimeout(msecs); + }); + } else + this.socket.setTimeout(msecs); }; @@ -1056,6 +1064,7 @@ ServerResponse.prototype.assignSocket = function(socket) { socket.on('close', onServerResponseClose); this.socket = socket; this.connection = socket; + this.emit('socket', socket); this._flush(); }; -- cgit v1.2.3