-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Agent Keep-Alive behavior #26357
Comments
/cc @mcollina |
I think this is buggy, and when passing cc @nodejs/http |
Update: I've noted that if const agentFalse = new http.Agent({
keepAlive: false,
keepAliveMsecs: 1000,
maxSockets: 0,
maxFreeSockets: 256
}) I can reproduce this behavior in all the latest releases of 6, 8, 10, and 11. |
I think this could be a nice good-first-issue. Maybe @delvedor would like to send a PR. |
Despite the confusing options, I'm not sure if it is a bug, I think it is working as intended. Consider the following example: const assert = require('assert');
const { Agent, get } = require('http');
const agent = new Agent({ keepAlive: false, maxSockets: 1 });
let socket;
function onResponse(response) {
response.resume();
}
function onSocket(sock) {
if (socket === undefined) {
socket = sock;
} else {
assert(sock === socket);
}
}
get({ host: 'example.com', agent }, onResponse).on('socket', onSocket);
get({ host: 'example.com', agent }, onResponse).on('socket', onSocket); If |
@lpinca it seems you are implying that setting keepAlive: false has nothing to do with sending the keep alive header, but it rather reflects the internal state of the queue. I think this is very confusing, and at least it should be documented if not changed. |
Yes exactly I think the
Maybe we can improve it somehow. |
@lpinca we are in disagreement. If the In other terms, if we pass In the example @delvedor has posted, there are more complicated combinations. For example: {
keepAlive: false,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256
} Is going to generate a I'm a bit puzzled by this issue. |
Sorry forgot to add "not" in my previous comment, please re-read, I've edited it. I don't think we are in disagreement. The example with |
Based on our discussion, should const agentFalseInf = new http.Agent({
keepAlive: false,
maxSockets: Infinity
}) send Based on our interpretation, should we ever send |
Basically The |
This matches our current behavior, but is it coherent with the meaning that we have given to the
This states that |
If |
Oks, so the naming generates this misunderstanding. |
@delvedor if you don't need connection pooling, don't use an agent and use the |
That's not what our docs says:
Maybe we should update this? Considering that setting Possibly we should include a table in the docs to explain the different options and behaviors, and how they effect |
PR-URL: nodejs#26412 Fixes: nodejs#26357 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Masashi Hirano <shisama07@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
I've encountered a strange behavior while using Agent Keep-Alive, and I'm not sure it is correct.
I've created a code example to show what I've discovered, pay attention to the configurations of the agents.
And this is the log:
If this is the expected behavior, can you explain why it works like so?
The text was updated successfully, but these errors were encountered: