Fix race condition in discovery manager causing duplicate aggregations #3471
+33
−8
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
This PR fixes a race condition in the discovery manager that causes duplicate capability aggregations when multiple concurrent requests arrive simultaneously at startup.
Problem
Without this fix, when multiple requests arrive concurrently:
This is a distinct issue from the race condition fixed in #3450.
Solution
Uses
singleflight.Groupto deduplicate concurrent capability aggregation requests:Changes
singleflight.Groupfield toDefaultManagerDiscover()method to wrap aggregation insingleFlight.Do()Testing
Existing tests pass. The race condition is most visible under high concurrency at startup when multiple clients connect simultaneously.