fix(inputs.prometheus): Add thread safety and proper cleanup for shared informer factories#18377
Merged
mstrandboge merged 3 commits intoinfluxdata:masterfrom Feb 23, 2026
Conversation
…ed informer factories The shared informer factory map is accessed concurrently by multiple plugin instances during Start/Stop, causing race conditions. The prior cleanup (delete from map) also leaked goroutines by not calling Shutdown() and could prematurely remove a factory still in use by another instance. Add a mutex to protect all access to the shared informer factory map, a reference counter to track active users per namespace, and an explicit Shutdown() call when the last user releases a factory.
srebhan
reviewed
Feb 19, 2026
Member
srebhan
left a comment
There was a problem hiding this comment.
Thanks @skartikey! One question...
srebhan
reviewed
Feb 19, 2026
…ed outside the lock
Contributor
|
Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
mstrandboge
approved these changes
Feb 23, 2026
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.
Summary
Follow-up to #18304 which added
delete(informerfactory, p.PodNamespace)inStop()to clean up shared informer factories. That fix addressed the resource leak but left three issues:Race condition: The
informerfactorymap is package-level shared state accessed concurrently by multiple plugin instances duringStart()/Stop()without synchronization, this is undefined behavior in Go and can panic at runtimeGoroutine leak: Deleting from the map doesn't stop the watcher goroutines spawned by
SharedInformerFactory.Start(), callingShutdown()is required to terminate themPremature deletion: If two instances share a factory (same namespace), the first to stop deletes it from under the second
Checklist
Related issues
related #18304