Skip to content

Do not raise the read error caused by Watch.stop() - #2823

Open
ilcm96 wants to merge 1 commit into
kubernetes-client:masterfrom
ilcm96:watch-stop-quietly
Open

ilcm96 wants to merge 1 commit into
kubernetes-client:masterfrom
ilcm96:watch-stop-quietly

Conversation

@ilcm96

@ilcm96 ilcm96 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

Watch.stop() shuts the response socket down (#2486) so that a stream blocked on a quiet watch returns at once. When stop() is called from another thread while stream() is blocked in a read, the read fails and stream() raises the error, e.g. urllib3.exceptions.ProtocolError: Response ended prematurely, so a normal stop looks like a connection failure. Following a pod log with Watch.stream(read_namespaced_pod_log, follow=True) is affected too.

This PR ends the stream quietly when reading fails after stop was requested, the same rule #2820 applied to SharedInformer. Errors raised without a stop request propagate as before, and the response is still closed and released.

Which issue(s) this PR fixes:

None filed.

Special notes for your reviewer:

How I tested it:

  • New unit test that stops a watch and a followed log from another thread during a blocked read; it fails before the change.
  • kind, no injected faults: stopping a quiet ConfigMap watch and a followed pod log from another thread raised ProtocolError in 5 of 5 runs each on master; now all 10 end normally.

Does this PR introduce a user-facing change?

`Watch.stream()` now ends normally instead of raising a read error such as `ProtocolError` when `Watch.stop()` is called from another thread while the stream is waiting for data, including pod log follows.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


Watch.stop() shuts the response socket down so that a stream blocked
on a quiet watch or a followed log returns at once. The blocked read
then fails, typically with urllib3 ProtocolError("Response ended
prematurely"), and Watch.stream() raised that error to the caller. A
caller that stops the stream from another thread, which is what the
shutdown is for, got an exception instead of the end of the stream.

When stop was requested, end the stream on any error raised while
reading it instead of raising it. Errors raised without a stop request
propagate as before, and the response is still closed and released.

Add a test that stops a watch stream and a followed log from another
thread while the read is blocked, and checks that the stream ends
without an error after the first item.
@kubernetes-prow kubernetes-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Dec 1, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ilcm96
Once this PR has been reviewed and has the lgtm label, please assign roycaihw 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
kubernetes-prow Bot requested review from roycaihw and yliaog December 1, 2026 14:08
@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 Dec 1, 2026
@roycaihw

roycaihw commented Dec 3, 2026

Copy link
Copy Markdown
Member

/assign @yliaog

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. kind/bug Categorizes issue or PR as related to a bug. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

3 participants