Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: fix Hub thread safety. #1388

Merged
merged 2 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Bump: Upgrade Apache HttpComponents Core to 5.0.3 (#1375)
* Enhancement: Make NoOpHub public (#1379)
* Fix: Do not bind transactions to scope by default. (#1376)
* Fix: fix Hub thread safety (#1388)

# 4.4.0-alpha.1

Expand Down
5 changes: 4 additions & 1 deletion sentry/src/main/java/io/sentry/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import io.sentry.protocol.User;
import io.sentry.util.Objects;
import java.io.Closeable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
Expand All @@ -20,7 +22,8 @@ public final class Hub implements IHub {
private volatile boolean isEnabled;
private final @NotNull Stack stack;
private final @NotNull TracesSampler tracesSampler;
private final @NotNull WeakHashMap<Throwable, ISpan> throwableToSpan = new WeakHashMap<>();
private final @NotNull Map<Throwable, ISpan> throwableToSpan =
Collections.synchronizedMap(new WeakHashMap<>());

public Hub(final @NotNull SentryOptions options) {
this(options, createRootStackItem(options));
Expand Down