Skip to content

Skip blank lines in watch event stream - #2778

Open
ilcm96 wants to merge 1 commit into
kubernetes-client:masterfrom
ilcm96:watch-skip-blank-lines
Open

ilcm96 wants to merge 1 commit into
kubernetes-client:masterfrom
ilcm96:watch-skip-blank-lines

Conversation

@ilcm96

@ilcm96 ilcm96 commented Nov 9, 2026

Copy link
Copy Markdown

What type of PR is this?

/kind bug

What this PR does / why we need it:

In the watch path of Watch.stream(), unmarshal_event() returns None for a blank or undecodable line, and stream() treats it as an event:

  • It yields None, so SharedInformer fails on event.get("type") and DynamicClient.watch() fails on event['object'].
  • It resets the one-time 410 retry. If every response has a blank line before a 410 Gone ERROR, a watch without timeout_seconds reconnects forever with the expired resourceVersion.

E.g. a response of "\n" followed by an ADDED event yields [None, {...}].

This PR skips None instead of yielding it or resetting the retry, and still checks stop() after a skipped line. The log/follow path still yields empty lines (#2372).

Which issue(s) this PR fixes:

None.

Special notes for your reviewer:

  • kubernetes.aio Watch has its own line handling and is not changed here.
  • Tested with new unit tests in kubernetes/watch/watch_test.py; the watch-path tests fail on master. A real API server does not send blank lines, so on a kind cluster I only ran the existing watch/informer e2e tests as a regression check.

Does this PR introduce a user-facing change?

`Watch.stream()` no longer yields `None` for blank or undecodable watch lines, and such lines no longer reset the one-time retry after a 410 Gone error.

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


Watch.stream() yielded None for a blank or undecodable line, which made
SharedInformer and the dynamic client fail on the event. The same branch
reset the 410 retry flag, so a repeated "blank line, 410 ERROR" sequence
reconnected forever with an expired resourceVersion.

Only yield, and reset the 410 retry flag, for decoded events. stop() is
still checked after a skipped line, and the follow (log) path is
unchanged. Add unit tests for these cases.
@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 Nov 9, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from roycaihw and yliaog November 9, 2026 11:29
@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 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 Nov 9, 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. 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.

1 participant