http: agent should cycle on close
This commit is contained in:
parent
49275524a5
commit
68f2aa2715
14
lib/http.js
14
lib/http.js
@ -1042,6 +1042,8 @@ Agent.prototype._establishNewConnection = function() {
|
|||||||
self._removeSocket(socket);
|
self._removeSocket(socket);
|
||||||
// unref the parser for easy gc
|
// unref the parser for easy gc
|
||||||
parsers.free(parser);
|
parsers.free(parser);
|
||||||
|
|
||||||
|
self._cycle();
|
||||||
});
|
});
|
||||||
|
|
||||||
parser.onIncoming = function(res, shouldKeepAlive) {
|
parser.onIncoming = function(res, shouldKeepAlive) {
|
||||||
@ -1068,13 +1070,21 @@ Agent.prototype._establishNewConnection = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.addListener('end', function() {
|
res.addListener('end', function() {
|
||||||
debug('AGENT request complete disconnecting.');
|
debug('AGENT request complete');
|
||||||
// For the moment we reconnect for every request. FIXME!
|
// For the moment we reconnect for every request. FIXME!
|
||||||
// All that should be required for keep-alive is to not reconnect,
|
// All that should be required for keep-alive is to not reconnect,
|
||||||
// but outgoingFlush instead.
|
// but outgoingFlush instead.
|
||||||
if (!req.shouldKeepAlive) socket.end();
|
if (!req.shouldKeepAlive) {
|
||||||
|
debug('AGENT socket.end()');
|
||||||
|
socket.end();
|
||||||
|
} else {
|
||||||
|
debug('AGENT socket keep-alive');
|
||||||
|
}
|
||||||
|
|
||||||
req.detachSocket(socket);
|
req.detachSocket(socket);
|
||||||
|
|
||||||
|
assert(!socket._httpMessage);
|
||||||
|
|
||||||
self._cycle();
|
self._cycle();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
33
test/simple/test-http-agent.js
Normal file
33
test/simple/test-http-agent.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
var common = require('../common');
|
||||||
|
var assert = require('assert');
|
||||||
|
var http = require('http');
|
||||||
|
|
||||||
|
var server = http.Server(function(req, res) {
|
||||||
|
res.writeHead(200);
|
||||||
|
res.end("hello world\n");
|
||||||
|
});
|
||||||
|
|
||||||
|
var responses = 0;
|
||||||
|
var N = 10;
|
||||||
|
var M = 10;
|
||||||
|
|
||||||
|
server.listen(common.PORT, function() {
|
||||||
|
for (var i = 0; i < N; i++) {
|
||||||
|
setTimeout(function () {
|
||||||
|
for (var j = 0; j < M; j++) {
|
||||||
|
http.get({ port: common.PORT, path: '/', }, function(res) {
|
||||||
|
console.log(res.statusCode);
|
||||||
|
if (++responses == N * M) server.close();
|
||||||
|
}).on('error', function(e) {
|
||||||
|
console.log(e.message);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, i);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
process.on('exit', function() {
|
||||||
|
assert.equal(N * M, responses);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user