[shell-operator] fix: protect shared informer lifecycle#917
Open
fuldaxxx wants to merge 3 commits into
Open
Conversation
Signed-off-by: Ruslan Gorbunov <ruslan.gorbunov@flant.com>
Signed-off-by: Ruslan Gorbunov <ruslan.gorbunov@flant.com>
Signed-off-by: Ruslan Gorbunov <ruslan.gorbunov@flant.com>
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.
Overview
Fix a shared-informer lifecycle bug in
FactoryStore(pkg/kube_events_manager/factory.go).A shared informer is a long-lived, store-owned resource, but its context used to be
derived from the first consumer that registered it. Cancelling that consumer's
context (e.g. when its monitor is stopped during a module reload) tore down the shared
informer for every other consumer still using it, silently freezing their snapshots
until the process was restarted. Ownership of the informer lifetime is moved to the
store, plus three supporting fixes (dead-factory detection, a narrower critical section,
and an un-swallowed error).
What this PR does / why we need it
Root cause.
NewFactoryStore()did not receive a context, andadd()derived thefactory context via
context.WithCancel(ctx)from the caller's context. The chainmgr.ctx → monitor.ctx → resourceInformer.ei.ctx → Start(ei.ctx) → add(ei.ctx)meantfactory.ctxwas a child of theei.ctxof whichever monitor created the factory first.Because factories are shared across monitors with the same
FactoryIndex(GVR + namespace + selectors), stopping that first monitor cancelled the shared informer
for all remaining consumers, while the refcount (
handlerRegistrations) was still > 0 sothe factory stayed cached. The surviving consumers were left attached to a dead informer.
This is a classic ownership bug: the lifetime of a shared, long-lived resource must be
owned by the store, not inherited from a transient consumer.
Impact. The failure is silent (no error,
HasSynced()on a stopped-but-once-syncedinformer returns
true) and only recoverable by restarting the process. Insurfaced as an empty
DexClientsnapshot inuser-authn: the hook feeds the desiredobject list into values, Helm prunes anything not in the list, so an empty
to the
dex-client-*Secret andOAuth2Clientbeing deleted — breaking OIDC login tothe cluster. Mass module reloads (e.g. during an upgrade) are the trigger w
Special notes for your reviewer