-
-
Notifications
You must be signed in to change notification settings - Fork 372
Closed
Description
Description
The SentryDependencyContainer.init can be called from a background thread. Before #5900 this was not problem, but since then the SentryDependencyContainer.initialize calls [[SentryDependencyContainer alloc] init]
sentry-cocoa/Sources/Sentry/SentryDependencyContainer.m
Lines 77 to 88 in d8ceea3
| + (void)initialize | |
| { | |
| if (self == [SentryDependencyContainer class]) { | |
| // We use two locks, because we don't want the dependencies to block the instance lock. | |
| // Using two locks speeds up the accessing the dependencies around 5%, which is worth having | |
| // the extra lock. Measured with self.measure in unit tests. | |
| sentryDependencyContainerInstanceLock = [[NSObject alloc] init]; | |
| sentryDependencyContainerDependenciesLock = [[NSObject alloc] init]; | |
| instance = [[SentryDependencyContainer alloc] init]; | |
| } | |
| } |
The init method uses the UIApplication.sharedApplication here
| _application = UIApplication.sharedApplication; |
If somebody calls SenrySDK.start from a BG thread, we access the SentryDependencyContainer.initialize also on a BG thread.
sentry-cocoa/Sources/Sentry/SentrySDKInternal.m
Lines 229 to 239 in d8ceea3
| + (void)startWithOptions:(SentryOptions *)options | |
| { | |
| // We save the options before checking for Xcode preview because | |
| // we will use this options in the preview | |
| startOption = options; | |
| if ([SentryDependencyContainer.sharedInstance.processInfoWrapper | |
| .environment[SENTRY_XCODE_PREVIEW_ENVIRONMENT_KEY] isEqualToString:@"1"]) { | |
| // Using NSLog because SentryLog was not initialized yet. | |
| NSLog(@"[SENTRY] [WARNING] SentrySDK not started. Running from Xcode preview."); | |
| return; | |
| } |
Test to reproduce
func testStartSDK_BGThread() {
let expectation = self.expectation(description: "Start on background thread")
DispatchQueue.global().async {
SentrySDK.start { options in
options.dsn = "whatever"
}
expectation.fulfill()
}
wait(for: [expectation], timeout: 5.0)
}Xcode stacktrace
