Skip to content

Commit

Permalink
ConcurrentModificationException when late meter filters are added
Browse files Browse the repository at this point in the history
Fixes micrometer-metrics#5489

Signed-off-by: Martin Bartoš <mabartos@redhat.com>
  • Loading branch information
mabartos committed Sep 24, 2024
1 parent 4b6b761 commit 84e5423
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ public abstract class MeterRegistry {
*/
private final Map<Id, Meter> preFilterIdToMeterMap = new HashMap<>();

// not thread safe; only needed when MeterFilter configured after Meters registered
/**
* Only needed when MeterFilter configured after Meters registered.
* Write/remove guarded by meterMapLock, otherwise unguarded
*/
private final Set<Id> stalePreFilterIds = new HashSet<>();

/**
Expand Down Expand Up @@ -829,7 +832,9 @@ public Config commonTags(String... tags) {
public synchronized Config meterFilter(MeterFilter filter) {
if (!meterMap.isEmpty()) {
logWarningAboutLateFilter();
stalePreFilterIds.addAll(preFilterIdToMeterMap.keySet());
synchronized (meterMapLock) {
stalePreFilterIds.addAll(preFilterIdToMeterMap.keySet());
}
}
MeterFilter[] newFilters = new MeterFilter[filters.length + 1];
System.arraycopy(filters, 0, newFilters, 0, filters.length);
Expand Down

0 comments on commit 84e5423

Please sign in to comment.