From 06e6f4260e0885e562eafe7c3c9d943269858427 Mon Sep 17 00:00:00 2001 From: stefanosiano Date: Thu, 6 Jul 2023 09:48:01 +0200 Subject: [PATCH 1/3] changed metrics listener map from HashMap to ConcurrentHashMap --- .../core/internal/util/SentryFrameMetricsCollector.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/internal/util/SentryFrameMetricsCollector.java b/sentry-android-core/src/main/java/io/sentry/android/core/internal/util/SentryFrameMetricsCollector.java index 7eb2f2b010..b3a24d237b 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/internal/util/SentryFrameMetricsCollector.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/internal/util/SentryFrameMetricsCollector.java @@ -19,10 +19,11 @@ import io.sentry.util.Objects; import java.lang.ref.WeakReference; import java.lang.reflect.Field; -import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,8 +35,8 @@ public final class SentryFrameMetricsCollector implements Application.ActivityLi private final @NotNull SentryOptions options; private @Nullable Handler handler; private @Nullable WeakReference currentWindow; - private final @NotNull HashMap listenerMap = - new HashMap<>(); + private final @NotNull Map listenerMap = + new ConcurrentHashMap<>(); private boolean isAvailable = false; private final WindowFrameMetricsManager windowFrameMetricsManager; From de43dc38d70906559aef00a36b6256376faf060e Mon Sep 17 00:00:00 2001 From: stefanosiano Date: Thu, 6 Jul 2023 09:51:26 +0200 Subject: [PATCH 2/3] updated changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42fb750f4f..6e495e829e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- Fix concurrent access to frameMetrics listener ([#2823](https://github.com/getsentry/sentry-java/pull/2823)) + ## 6.25.0 ### Features From e35f9cd3d393ffee06a945bd6feeed52b4fdc32b Mon Sep 17 00:00:00 2001 From: stefanosiano Date: Fri, 7 Jul 2023 17:47:04 +0200 Subject: [PATCH 3/3] trackedWindows is now a CopyOnWriteArraySet --- .../core/internal/util/SentryFrameMetricsCollector.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/internal/util/SentryFrameMetricsCollector.java b/sentry-android-core/src/main/java/io/sentry/android/core/internal/util/SentryFrameMetricsCollector.java index b3a24d237b..f8957982e7 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/internal/util/SentryFrameMetricsCollector.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/internal/util/SentryFrameMetricsCollector.java @@ -19,11 +19,11 @@ import io.sentry.util.Objects; import java.lang.ref.WeakReference; import java.lang.reflect.Field; -import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArraySet; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -31,7 +31,7 @@ @ApiStatus.Internal public final class SentryFrameMetricsCollector implements Application.ActivityLifecycleCallbacks { private final @NotNull BuildInfoProvider buildInfoProvider; - private final @NotNull Set trackedWindows = new HashSet<>(); + private final @NotNull Set trackedWindows = new CopyOnWriteArraySet<>(); private final @NotNull SentryOptions options; private @Nullable Handler handler; private @Nullable WeakReference currentWindow;