-
Notifications
You must be signed in to change notification settings - Fork 538
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
Reintroduce timeout and keep-alive for watch requests to match client-go #2131
base: main
Are you sure you want to change the base?
Conversation
|
Welcome @Alabate! |
a82c51a
to
4113110
Compare
4113110
to
ded25aa
Compare
This will send sends keep-alive probes to the server every 30 seconds. These features were present prior to the 1.0 refactor but were inadvertently removed.
ded25aa
to
8561542
Compare
There is also a |
I agree that it should, but when I tried it didn't work, so I though I did not understand the documentation. But in the end, I think it's more because of this issue: nodejs/node#47137 To confirm it, I ran the following snippet that simply create an agent and a request and try to read the import * as protocol from 'node:http';
const agent = new protocol.Agent({
keepAlive: true,
keepAliveMsecs: 3000,
});
console.log('========= Protocol ', agent.protocol, '==========');
const req = protocol.request(`${agent.protocol}//google.com`, { agent: agent }, (res) => {
logKeepaliveSocketStatus(res.socket);
req.socket.setKeepAlive(true, 4000);
logKeepaliveSocketStatus(res.socket);
});
req.end();
function logKeepaliveSocketStatus(socket) {
const kSetKeepAlive = Object.getOwnPropertySymbols(socket).find(
(sym) => sym.description === 'kSetKeepAlive',
);
const kSetKeepAliveInitialDelay = Object.getOwnPropertySymbols(socket).find(
(sym) => sym.description === 'kSetKeepAliveInitialDelay',
);
console.log('----- Socket status -----');
console.log('kSetKeepAlive:', socket[kSetKeepAlive]);
console.log('kSetKeepAliveInitialDelay:', socket[kSetKeepAliveInitialDelay]);
} When I execute this script with the
However, if I replace
And in our case we use the https agent |
Please add unit tests also. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Alabate, anandfresh The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
As much as I don't like the workaround here, I haven't been able to find a better way with the current project setup. It's also surprising that no one has tried to fix nodejs/node#47137. LGTM once there are tests. |
This will send sends keep-alive probes to the server every 30 seconds. These features were present prior to the 1.0 but were inadvertently removed.
Fixes #2127
Previous relevant issues:
Implementation details
Setting
requestInit.timeout = 30000
is equivalent tosocket.setTimeout(30000)
as you can see in the sources.One of the solution suggested in #2127 was to use the keepAlive of the
http.Agent
. But as documented here, that's just a boolean that instruct the agent that we want sockets to be re-used. We want to send packets at a fixed rate to know when a connection is broken. This can be done with thesocket.setKeepAlive()
method, but to use it, we need to access the socket object.I managed to access the socket and call
setKeepAlive()
, but only after theawait fetch()
, when the response is already arriving. That's the only way I found to access the socket. The Agent create the socket, but there is no event to know when a socket created, you can just access them by list like I did. There is asocket
event on the request object, butnode-fetch
abstract it away, and I couldn't find a clean way to access it (See discussion that request this feature).The only way I've found to get the socket before the request was by monkey-patching the
agent.createConnection()
, but I think this solution is worse.