From: Ryan Dahl Date: Sat, 22 Jan 2011 01:39:45 +0000 (-0800) Subject: Fix test-http-allow-req-after-204-res X-Git-Tag: v0.3.6~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4612b07604bf654bc521dd0473f82b166deb7412;p=platform%2Fupstream%2Fnodejs.git Fix test-http-allow-req-after-204-res Agent queue waits for connecting sockets. --- 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(); }