Skip to content

Add example for enabling TCP keepalive via socket_options - #2699

Closed
thev1ndu wants to merge 1 commit into
kubernetes-client:masterfrom
thev1ndu:dynamic-keepalive-example
Closed

Add example for enabling TCP keepalive via socket_options#2699
thev1ndu wants to merge 1 commit into
kubernetes-client:masterfrom
thev1ndu:dynamic-keepalive-example

Conversation

@thev1ndu

Copy link
Copy Markdown

What type of PR is this?

/kind documentation

What this PR does / why we need it:

Configuration.socket_options is already passed through to the underlying urllib3 pool, but there is no example showing how to use it. Long-lived requests such as watches or follow=True log streams can hang when a connection is silently dropped by a load balancer or firewall. Enabling TCP keepalive lets the kernel detect the dead peer and close the socket. This adds examples/tcp_keepalive.py and lists it in the examples README. The helper only sets the platform-specific options (TCP_KEEPIDLE and friends) when they are available.

Which issue(s) this PR fixes:

Fixes #2067

Special notes for your reviewer:

Example only, no library code changes.

Does this PR introduce a user-facing change?

NONE

Configuration.socket_options is already wired through to urllib3, but
there is no example showing how to use it. Long-lived watches and log
streams can hang when a connection is silently dropped; TCP keepalive
lets the kernel detect the dead peer. Add an example and list it in the
examples README.

Fixes kubernetes-client#2067
@kubernetes-prow kubernetes-prow Bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. kind/documentation Categorizes issue or PR as related to documentation. labels Aug 31, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: thev1ndu
Once this PR has been reviewed and has the lgtm label, please assign yliaog for approval. For more information see the Code Review Process.

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

Details Needs approval from an approver in each of these files:

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

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Invalid commit message issues detected

Invalid commit messages

Keywords which can automatically close issues and hashtag(#) mentions are not allowed.

  • 1a3b51b Add example for enabling TCP keepalive via socket_options

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@kubernetes-prow
kubernetes-prow Bot requested review from roycaihw and yliaog August 31, 2026 07:00
@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 31, 2026
@aojea

aojea commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Long-lived requests such as watches or follow=True log streams can hang when a connection is silently dropped by a load balancer or firewall

TCP_KEEPALIVE is not the right solution, it does not work as people thing it does, once the connection is established the keepalives are not sent periodically ... http2 ping frames is the solution to idle connections and middleware silent drops kubernetes/kubernetes#95981

@thev1ndu thev1ndu closed this Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. kind/documentation Categorizes issue or PR as related to documentation. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set tcp keepalive for http connections

2 participants