Skip to content

Keep SharedInformer resourceVersion before an event dropped on stop - #2824

Open
ilcm96 wants to merge 1 commit into
kubernetes-client:masterfrom
ilcm96:informer-rv-after-cache
Open

ilcm96 wants to merge 1 commit into
kubernetes-client:masterfrom
ilcm96:informer-rv-after-cache

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:

SharedInformer can be stopped and started again, keeping its cache and resource version, for example when a leader loses and regains its lease. If stop() lands after Watch has read an event but before the informer applies it, the loop drops the event, but the finally block still copied Watch.resource_version, which already pointed at that event. The next start() resumes after it without a relist, so with resync_period=0 the event is lost for good and the cache keeps the old object until it changes again.

This happens without any injected timing. On a kind cluster, one process patched 20 ConfigMaps (~4 KiB each, ~220 events/s) while the informer was stopped at a random moment and started again, 200 times. On master, 6 of the 200 restarts lost an event and left that ConfigMap stale in the cache (21 of 200 at ~860 events/s). With this change, none did in either run.

This PR stops copying the resource version in finally. The loop already syncs it after the stop check for every processed event, so other paths, including 410 handling, are unchanged.

Which issue(s) this PR fixes:

None filed.

Special notes for your reviewer:

An event whose cache update fails (e.g. a raising key_func) is still skipped, as before, because retrying it would fail the same way in a loop.

How I tested it:

  • New unit tests in kubernetes/test/test_informer.py: test_event_received_after_stop_is_not_skipped_on_restart fails on master; test_events_after_failing_cache_update_are_still_applied pins the existing behaviour.
  • kind: the stop/start loop above, and kubernetes/e2e_test/test_informer.py and test_watch.py (7 passed, same as master).

Does this PR introduce a user-facing change?

Fix SharedInformer skipping a watch event that was received right before stop() when it is started again.

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


When stop() was requested after Watch yielded an event, the loop
dropped that event, but the finally block still copied
Watch.resource_version, which had already advanced past it. The next
start() resumed after the event, so it was lost until the next relist.

Stop copying the Watch's resource version in the finally block; the
loop already syncs it for every processed event. Add unit tests for a
restart after a dropped event and for an event that fails key_func.
@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
kubernetes-prow Bot requested review from roycaihw and yliaog December 1, 2026 14:08
@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 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 kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 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/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants