Skip to content

Reintroduce timeout and keep-alive for watch requests to match client-go #2367

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged

Conversation

rossanthony
Copy link
Contributor

@rossanthony rossanthony commented Apr 10, 2025

Thanks to @Alabate for opening the initial PR with this fix: #2131

This PR includes Alabate's fix + unit test coverage. Below is the original PR description copied here for reference:


This will send 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 to socket.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 the socket.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 the await 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 a socket event on the request object, but node-fetch abstract it away, and I couldn't find a clean way to access it (node-fetch/node-fetch#1720 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.

const _createConnection = agent.createConnection;
agent.createConnection = function (...args) {
  const socket = _createConnection.apply(agent, args);
  socket.setTimeout(3000);
  socket.setKeepAlive(true, 3000);
  return socket;
}

Copy link

linux-foundation-easycla bot commented Apr 10, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: rossanthony / name: Ross Anthony (fe8d1c1)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Apr 10, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @rossanthony!

It looks like this is your first PR to kubernetes-client/javascript 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/javascript has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 10, 2025
@rossanthony
Copy link
Contributor Author

/easycla

@rossanthony rossanthony force-pushed the fix-watch-keepalive branch from a1d444f to fe8d1c1 Compare April 10, 2025 16:20
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Apr 10, 2025
@brendandburns
Copy link
Contributor

Thanks for finishing this up. I'll let @cjihrig have the final LGTM, but looks good to me.

/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 10, 2025
Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brendandburns, cjihrig, rossanthony

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [brendandburns,cjihrig]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 11, 2025
@k8s-ci-robot k8s-ci-robot merged commit c3c96cb into kubernetes-client:main Apr 11, 2025
8 checks passed
@rossanthony
Copy link
Contributor Author

@brendandburns or @cjihrig what's the process for getting a new release cut?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Watch keepalive not working anymore with 1.0.0
4 participants