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

ref: Make SentrySDK.replay.start() thread safe #4455

Merged
merged 6 commits into from
Oct 18, 2024
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 @@ -30,6 +30,7 @@ via the option `swizzleClassNameExclude`.
- Speed up getBinaryImages (#4435) for finishing transactions and capturing events
- Align SDK dispatch queue names (#4442) to start with `io.sentry`
- Use UInts in envelope deserialization (#4441)
- Make `SentrySDK.replay.start()` thread safe (#4455)

## 8.38.0

Expand Down
24 changes: 17 additions & 7 deletions Sources/Sentry/SentryReplayApi.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#if SENTRY_TARGET_REPLAY_SUPPORTED

# import "SentryHub+Private.h"
# import "SentryInternalCDefines.h"
# import "SentryOptions+Private.h"
# import "SentrySDK+Private.h"
# import "SentrySessionReplayIntegration+Private.h"
Expand Down Expand Up @@ -37,21 +38,30 @@
[replayIntegration resume];
}

- (void)start
- (void)start SENTRY_DISABLE_THREAD_SANITIZER("double-checked lock produce false alarms")
{
SentrySessionReplayIntegration *replayIntegration
= (SentrySessionReplayIntegration *)[SentrySDK.currentHub
getInstalledIntegration:SentrySessionReplayIntegration.class];

// Start could be misused and called multiple times, causing it to
// be initialized more than once before being installed.
// Synchronizing it will prevent this problem.
if (replayIntegration == nil) {
SentryOptions *currentOptions = SentrySDK.currentHub.client.options;
replayIntegration =
[[SentrySessionReplayIntegration alloc] initForManualUse:currentOptions];
@synchronized(self) {
replayIntegration = (SentrySessionReplayIntegration *)[SentrySDK.currentHub
getInstalledIntegration:SentrySessionReplayIntegration.class];

Check warning on line 53 in Sources/Sentry/SentryReplayApi.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryReplayApi.m#L51-L53

Added lines #L51 - L53 were not covered by tests
if (replayIntegration == nil) {
SentryOptions *currentOptions = SentrySDK.currentHub.client.options;
replayIntegration =
[[SentrySessionReplayIntegration alloc] initForManualUse:currentOptions];

Check warning on line 57 in Sources/Sentry/SentryReplayApi.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryReplayApi.m#L55-L57

Added lines #L55 - L57 were not covered by tests

[SentrySDK.currentHub addInstalledIntegration:replayIntegration
name:NSStringFromClass(SentrySessionReplay.class)];
[SentrySDK.currentHub
addInstalledIntegration:replayIntegration
name:NSStringFromClass(SentrySessionReplay.class)];

Check warning on line 61 in Sources/Sentry/SentryReplayApi.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryReplayApi.m#L59-L61

Added lines #L59 - L61 were not covered by tests
}
}
}

[replayIntegration start];
}

Expand Down
Loading