Skip to content

[Bug] runWatcher Registry Poisoning leads to Permanent Stale Cache for Cluster Context #5162

@KumarADITHYA123

Description

@KumarADITHYA123

Description

The caching architecture relies on watcherRegistry to ensure only a single cache listener goroutine executes per cluster context. CheckForChanges() records the contextKey in this map natively to lock it before invoking go runWatcher(ctx, k8scache, contextKey, kContext).

However, runWatcher() suffers from a state mismanagement issue. It has several early-exit conditions during startup that abort the thread:

  1. kContext.RESTConfig() errs.
  2. dynamic.NewForConfig(config) errs.
  3. discoveryClient.ServerPreferredResources() errs.

When runWatcher bails out on any of these checks, it simply returns nil and dies. Crucially, it does not unregister its assigned contextKey from the watcherRegistry.

Impact

As a result, the watcherRegistry believes an active goroutine is maintaining caching for this cluster forever. Subsequent calls dynamically bypass watcher startup:

	if _, loaded := watcherRegistry.Load(contextKey); loaded {
		return // Silently assumes thread is active tracking Kubernetes cache
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions