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

Fixed deadlock during offline start. #3959

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions Sources/Sentry/SentryHttpTransport.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#import "SentryNSURLRequest.h"
#import "SentryNSURLRequestBuilder.h"
#import "SentryOptions.h"
#import "SentrySDK+Private.h"
#import "SentrySerialization.h"
#import "SentrySwift.h"

Expand Down Expand Up @@ -268,6 +269,11 @@ - (void)sendAllCachedEnvelopes
SENTRY_LOG_DEBUG(@"sendAllCachedEnvelopes start.");

@synchronized(self) {
if (nil == SentrySDK.currentHub) {
SENTRY_LOG_DEBUG(@"Not started yet.");
return;
}

if (self.isSending || ![self.requestManager isReady]) {
SENTRY_LOG_DEBUG(@"Already sending.");
return;
Expand Down
3 changes: 0 additions & 3 deletions Sources/Sentry/SentrySDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ + (void)initialize
+ (SentryHub *)currentHub
{
@synchronized(self) {
if (nil == currentHub) {
currentHub = [[SentryHub alloc] initWithClient:nil andScope:nil];
}
Comment on lines -76 to -78
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h: We cant remove this right now. It will break a lot of tests, we need to find another solution.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain motivation behind this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it'll try to send envelopes to that hub, they'll be just dropped. And transport should wait for a hub with a client to send something.
May be we could check scope, before enrich it.

if (scope)
        [SentryDependencyContainer.sharedInstance.crashWrapper enrichScope:scope];

But that's strange solution and it could happen again in different part of code. Sentry should try to send something only when SentrySDK start finishes. With changes from this PR it's guaranteed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain motivation behind this?

This was probably put in place to make writing tests easier.
As you can see, all unit tests are broken right now.
But I agree that we need to check if the SDK is initialized before starting to use the hub.

return currentHub;
}
}
Expand Down
Loading