Skip to content
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

doc && http: fix agent default value for keepAlive #51115

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ changes:
header is always sent when using an agent except when the `Connection`
header is explicitly specified or when the `keepAlive` and `maxSockets`
options are respectively set to `false` and `Infinity`, in which case
`Connection: close` will be used. **Default:** `false`.
`Connection: close` will be used. **Default:** `true`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.keepAlive = this.options.keepAlive || false;

The default value is false.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

So a another line in doc is misleading.

https://github.com/nodejs/node/pull/51115/files#diff-d692ac4524379ec6a1201165e8ff8d3267c8130e07014e8221ebf7e6f80c6641R183-R184

Because

globalAgent: new Agent({ keepAlive: true, scheduling: 'lifo', timeout: 5000 }),

I understand the default value for a new Agent is falsy keepAlive, but the "default" globalAgent is set to true.

~ » nvm use system
Now using system version of node: v20.10.0 (npm v10.2.5)
--------------------------------------------------------------------------------------------------
~ » node -pe 'const {keepAlive, keepAliveMsecs} = http.globalAgent; ({keepAlive, keepAliveMsecs})'
{ keepAlive: true, keepAliveMsecs: 1000 }
~ » nvm use 18
Now using node v18.19.0 (npm v10.2.3)
--------------------------------------------------------------------------------------------------
~ » node -pe 'const {keepAlive, keepAliveMsecs} = http.globalAgent; ({keepAlive, keepAliveMsecs})'
{ keepAlive: false, keepAliveMsecs: 1000 }

To be complete, in our organization (https://www.radiofrance.fr/) we had some surprises with this change in our kubernetes infrastructure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right: the misleading line is the one you linked above. In #43522 I changed some options for the default agent (while leaving the constructor behavior untouched).
Could you please update this PR to fix that offending line instead of the one you proposed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I hope my changes are what you expect.

* `keepAliveMsecs` {number} When using the `keepAlive` option, specifies
the [initial delay][]
for TCP Keep-Alive packets. Ignored when the
Expand Down