Add an opt-in TCP keepalive option to the sync client - #2693
Open
chala2001 wants to merge 1 commit into
Open
Conversation
Long lived requests such as watches are dropped silently when an idle proxy or load balancer closes the connection, because the client never sends anything on it. Setting keep_alive on the Configuration now asks the kernel for the same keepalive timings client-go dials with: probe after 30s idle, then every 15s, giving up after 9 probes. socket_options still wins if it is set, so existing callers are unaffected.
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: chala2001 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
/kind feature
What this PR does / why we need it:
An idle watch sends nothing on its connection, so a proxy or load balancer in
the path is free to drop it, and the client only finds out on the next read.
client-go avoids this by dialling with a keepalive
(transport/cache.go),
while the Python client asks the kernel for nothing.
Configuration.socket_optionsalready reaches urllib3, so the plumbing exists.What is missing is a supported way to turn keepalive on without hand-writing
platform specific socket tuples.
This adds
Configuration.keep_alive, off by default:The timings match what client-go actually asks the kernel for. Its
Dialer.KeepAlive: 30 * time.Secondbecomes the idle time, and Go leaves theprobe interval and count at its own defaults, so on Linux client-go ends up
with
TCP_KEEPIDLE=30,TCP_KEEPINTVL=15,TCP_KEEPCNT=9. The helper usesthose three values.
Two details worth flagging:
default_socket_optionsrather thanreplacing them. urllib3 swaps its defaults for whatever list it is handed
instead of merging, so building on them keeps
TCP_NODELAYin place.hasattrguarded. macOS spells the idle timeTCP_KEEPALIVEand has no
TCP_KEEPIDLE, so a bare reference would raiseAttributeErrorat import time there.
socket_optionsstill wins when set, so callers already passing their own listare unaffected.
The layout follows #2671: the logic is hand-written in
kubernetes/utils/, andthe generated client gets a small
scripts/keepalive_patch.diffthatupdate-client.shre-applies after regeneration.Sync client only. The asyncio client stores
socket_optionsbut never reads it_create_connectorbuilds anaiohttp.TCPConnector, which takes no socketoptions - so parity there is a separate change.
Which issue(s) this PR fixes:
Fixes #2067
Special notes for your reviewer:
kubernetes/utils/keepalive_test.pycovers the timings, the preserved urllib3defaults, the macOS fallback and the platform guard, and checks the pool
manager actually receives the options. Not covered: whether probes reach the
wire, which needs a real idle connection.
#2067 is cross-linked from #1841. That one is the websocket exec stream dying
after 300s idle, which needs ping frames in
ws_client.py- a differentmechanism, not fixed here.
Does this PR introduce a user-facing change?