Repository navigation
Honor Watch.stop() called while the watch request is in flight - #2799
Merged
kubernetes-prow[bot] merged 1 commit intoNov 21, 2026
Merged
kubernetes-prow[bot] merged 1 commit into
kubernetes-prow[bot] merged 1 commit into
Conversation
If stop() is called from another thread before the watch response arrives, there is no response to shut down and the stop flag is only checked after the first line. The stream then blocks until an event arrives, possibly forever on a quiet resource. Reconnect requests have the same window. Check the stop flag right after the response is stored and before reading it. Add unit tests for the initial and reconnect requests.
Contributor
|
thanks for the PR /lgtm |
Contributor
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ilcm96, yliaog The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
kubernetes-prow
Bot
merged commit Nov 21, 2026
d9d9145
into
kubernetes-client:master
10 checks passed
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 bug
What this PR does / why we need it:
If
Watch.stop()is called from another thread whileWatch.stream()waits for the watch response,stop()has no socket to shut down (#2486), andstream()checks the stop flag only after reading the first line. The stream then blocks until an event arrives, possibly forever on a quiet resource withouttimeout_seconds. Reconnect requests have the same window.This PR checks the stop flag after storing the response and before reading it. Since
stop()sets the flag before checking the response, either the stream sees the flag orstop()shuts down the socket.Which issue(s) this PR fixes:
None reported. Follow-up to #2486, which added the socket shutdown in
stop().Special notes for your reviewer:
stop(), a non-2xx raw response from a hand-written function ends the stream without raising; generated APIs and the dynamic client raise earlier.kubernetes.aioalready checks the flag before reading.test_watch_stop_during_requestandtest_watch_stop_during_reconnect_requestinkubernetes/watch/watch_test.py, which fail on master. The window is too short to hit on a real API server, so kind was used only for the existing watch/informer e2e tests.Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: