Fixes #877. Don't wait for socket pool to establish connections.
Thanks to Yann Biancheri for putting together an initial test.
This commit is contained in:
parent
f78f654131
commit
efca5456b8
12
lib/http.js
12
lib/http.js
@ -1152,12 +1152,6 @@ Agent.prototype.appendMessage = function(options) {
|
|||||||
this.queue.push(req);
|
this.queue.push(req);
|
||||||
req._queue = this.queue;
|
req._queue = this.queue;
|
||||||
|
|
||||||
/*
|
|
||||||
req.on('finish', function () {
|
|
||||||
self._cycle();
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
this._cycle();
|
this._cycle();
|
||||||
|
|
||||||
return req;
|
return req;
|
||||||
@ -1374,8 +1368,6 @@ Agent.prototype._cycle = function() {
|
|||||||
var first = this.queue[0];
|
var first = this.queue[0];
|
||||||
if (!first) return;
|
if (!first) return;
|
||||||
|
|
||||||
var haveConnectingSocket = false;
|
|
||||||
|
|
||||||
// First try to find an available socket.
|
// First try to find an available socket.
|
||||||
for (var i = 0; i < this.sockets.length; i++) {
|
for (var i = 0; i < this.sockets.length; i++) {
|
||||||
var socket = this.sockets[i];
|
var socket = this.sockets[i];
|
||||||
@ -1395,13 +1387,11 @@ Agent.prototype._cycle = function() {
|
|||||||
self._cycle(); // try to dispatch another
|
self._cycle(); // try to dispatch another
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socket._httpConnecting) haveConnectingSocket = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no sockets are connecting, and we have space for another we should
|
// If no sockets are connecting, and we have space for another we should
|
||||||
// be starting a new connection to handle this request.
|
// be starting a new connection to handle this request.
|
||||||
if (!haveConnectingSocket && this.sockets.length < this.maxSockets) {
|
if (this.sockets.length < this.maxSockets) {
|
||||||
this._establishNewConnection();
|
this._establishNewConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
49
test/simple/test-regress-GH-877.js
Normal file
49
test/simple/test-regress-GH-877.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
var common = require('../common');
|
||||||
|
var http = require('http');
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
|
var N = 20;
|
||||||
|
var responses = 0;
|
||||||
|
var maxQueued = 0;
|
||||||
|
|
||||||
|
debugger;
|
||||||
|
|
||||||
|
var agent = http.getAgent('127.0.0.1', common.PORT);
|
||||||
|
agent.maxSockets = 10;
|
||||||
|
|
||||||
|
var server = http.createServer(function (req, res) {
|
||||||
|
res.writeHead(200);
|
||||||
|
res.end('Hello World\n');
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(common.PORT, "127.0.0.1", function() {
|
||||||
|
for (var i = 0; i < N; i++) {
|
||||||
|
var options = {
|
||||||
|
host: '127.0.0.1',
|
||||||
|
port: common.PORT,
|
||||||
|
};
|
||||||
|
|
||||||
|
debugger;
|
||||||
|
|
||||||
|
var req = http.get(options, function(res) {
|
||||||
|
if (++responses == N) {
|
||||||
|
server.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(req.agent, agent);
|
||||||
|
|
||||||
|
console.log('Socket: ' + agent.sockets.length +
|
||||||
|
'/' + agent.maxSockets +
|
||||||
|
' queued: '+ agent.queue.length);
|
||||||
|
|
||||||
|
if (maxQueued < agent.queue.length) {
|
||||||
|
maxQueued = agent.queue.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('exit', function() {
|
||||||
|
assert.ok(responses == N);
|
||||||
|
assert.ok(maxQueued <= 10);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user