getsentry / sentry-cocoa

The official Sentry SDK for iOS, tvOS, macOS, watchOS.
https://sentry.io/for/cocoa/
MIT License
773 stars 306 forks source link

Fixed deadlock during offline start. #3959

Closed molind closed 2 weeks ago

molind commented 3 weeks ago

:scroll: Description

See details in #3956

:bulb: Motivation and Context

Sentry deadlocked during offline startup.

:green_heart: How did you test it?

I've added sleep into the crash wrapper. And when background thread tried to send envelope it locked SentrySdk @synchronized(self).

- (NSDictionary *)systemInfo
{
    static NSDictionary *sharedInfo = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken,
                  ^{
        sleep(5);
        sharedInfo = SentryDependencyContainer.sharedInstance.crashReporter.systemInfo;
    });
    return sharedInfo;
}

:pencil: Checklist

You have to check all boxes before merging:

:crystal_ball: Next steps

molind commented 3 weeks ago

I've checked 8.21, when it worked without issues.

It creates SentryHub without enriching scope:

- (instancetype)initWithClient:(nullable SentryClient *)client
                      andScope:(nullable SentryScope *)scope
{
    if (self = [super init]) {
        _client = client;
        _scope = scope;
        _sessionLock = [[NSObject alloc] init];
        _integrationsLock = [[NSObject alloc] init];
        _installedIntegrations = [[NSMutableArray alloc] init];
        _installedIntegrationNames = [[NSMutableSet alloc] init];
        _crashWrapper = [SentryCrashWrapper sharedInstance];
        _errorsBeforeSession = 0;
    }
    return self;
}

And there is no systemInfo call and no deadlock.

philipphofmann commented 2 weeks ago

Thanks for all the context in this PR and in https://github.com/getsentry/sentry-cocoa/issues/3956, which helped us reproduce the issue. As this PR is only a workaround and doesn't fix the underlying issue, I opened https://github.com/getsentry/sentry-cocoa/pull/3970 to fix the underlying issue. We can close this.