From 4612b07604bf654bc521dd0473f82b166deb7412 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 21 Jan 2011 17:39:45 -0800 Subject: [PATCH] Fix test-http-allow-req-after-204-res Agent queue waits for connecting sockets. --- lib/http.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/http.js b/lib/http.js index d70c9cf..8327342 100644 --- a/lib/http.js +++ b/lib/http.js @@ -951,11 +951,17 @@ Agent.prototype._establishNewConnection = function() { // Grab a new "socket". Depending on the implementation of _getConnection // this could either be a raw TCP socket or a TLS stream. var socket = this._getConnection(this.host, this.port, function () { + socket._httpConnecting = false; self.emit('connect'); // mostly for the shim. debug("Agent _getConnection callback"); self._cycle(); }); + // Use this special mark so that we know if the socket is connecting. + // TODO: come up with a standard way of specifying that a stream is being + // connected across tls and net. + socket._httpConnecting = true; + this.sockets.push(socket); // Add a parser to the socket. @@ -1109,11 +1115,14 @@ Agent.prototype._getConnection = function(host, port, cb) { // waiting sockets. If a waiting socket cannot be found, it will // start the process of establishing one. Agent.prototype._cycle = function() { - debug("Agent _cycle"); + debug("Agent _cycle sockets=" + this.sockets.length + " queue=" + this.queue.length); var first = this.queue[0]; if (!first) return; + + var haveConnectingSocket = false; + // First try to find an available socket. for (var i = 0; i < this.sockets.length; i++) { var socket = this.sockets[i]; @@ -1126,11 +1135,13 @@ Agent.prototype._cycle = function() { first.assignSocket(socket); return; } + + if (socket._httpConnecting) haveConnectingSocket = true; } - // Otherwise see if we should be starting a new connection to handle - // this. - if (this.sockets.length < this.maxSockets) { + // If no sockets are connecting, and we have space for another we should + // be starting a new connection to handle this request. + if (!haveConnectingSocket && this.sockets.length < this.maxSockets) { this._establishNewConnection(); } -- 2.7.4