From b11c6c178f312d65a88280e1aa1cdf220296b524 Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Tue, 19 Sep 2023 16:23:34 +0200 Subject: [PATCH 01/38] Update SentryCrashIntegration.m --- Sources/Sentry/SentryCrashIntegration.m | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Sources/Sentry/SentryCrashIntegration.m b/Sources/Sentry/SentryCrashIntegration.m index ee0ee8738bf..efd396b3acc 100644 --- a/Sources/Sentry/SentryCrashIntegration.m +++ b/Sources/Sentry/SentryCrashIntegration.m @@ -241,7 +241,7 @@ + (void)enrichScope:(SentryScope *)scope crashWrapper:(SentryCrashWrapper *)cras // DEVICE - NSMutableDictionary *deviceData = [NSMutableDictionary new]; + __block NSMutableDictionary *deviceData = [NSMutableDictionary new]; #if TARGET_OS_SIMULATOR [deviceData setValue:@(YES) forKey:@"simulator"]; @@ -272,16 +272,18 @@ + (void)enrichScope:(SentryScope *)scope crashWrapper:(SentryCrashWrapper *)cras [deviceData setValue:locale forKey:LOCALE_KEY]; #if SENTRY_HAS_UIKIT - - NSArray *appWindows = SentryDependencyContainer.sharedInstance.application.windows; - if ([appWindows count] > 0) { - UIScreen *appScreen = appWindows.firstObject.screen; - if (appScreen != nil) { - [deviceData setValue:@(appScreen.bounds.size.height) forKey:@"screen_height_pixels"]; - [deviceData setValue:@(appScreen.bounds.size.width) forKey:@"screen_width_pixels"]; + [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchSyncOnMainQueue:^{ + NSArray *appWindows + = SentryDependencyContainer.sharedInstance.application.windows; + if ([appWindows count] > 0) { + UIScreen *appScreen = appWindows.firstObject.screen; + if (appScreen != nil) { + [deviceData setValue:@(appScreen.bounds.size.height) + forKey:@"screen_height_pixels"]; + [deviceData setValue:@(appScreen.bounds.size.width) forKey:@"screen_width_pixels"]; + } } - } - + }]; #endif [scope setContextValue:deviceData forKey:DEVICE_KEY]; From 23da6cc2f4db889eba084fe71d31b193985cc0f6 Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Tue, 19 Sep 2023 16:32:36 +0200 Subject: [PATCH 02/38] Revert "Update SentryCrashIntegration.m" This reverts commit b11c6c178f312d65a88280e1aa1cdf220296b524. --- Sources/Sentry/SentryCrashIntegration.m | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Sources/Sentry/SentryCrashIntegration.m b/Sources/Sentry/SentryCrashIntegration.m index efd396b3acc..ee0ee8738bf 100644 --- a/Sources/Sentry/SentryCrashIntegration.m +++ b/Sources/Sentry/SentryCrashIntegration.m @@ -241,7 +241,7 @@ + (void)enrichScope:(SentryScope *)scope crashWrapper:(SentryCrashWrapper *)cras // DEVICE - __block NSMutableDictionary *deviceData = [NSMutableDictionary new]; + NSMutableDictionary *deviceData = [NSMutableDictionary new]; #if TARGET_OS_SIMULATOR [deviceData setValue:@(YES) forKey:@"simulator"]; @@ -272,18 +272,16 @@ + (void)enrichScope:(SentryScope *)scope crashWrapper:(SentryCrashWrapper *)cras [deviceData setValue:locale forKey:LOCALE_KEY]; #if SENTRY_HAS_UIKIT - [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchSyncOnMainQueue:^{ - NSArray *appWindows - = SentryDependencyContainer.sharedInstance.application.windows; - if ([appWindows count] > 0) { - UIScreen *appScreen = appWindows.firstObject.screen; - if (appScreen != nil) { - [deviceData setValue:@(appScreen.bounds.size.height) - forKey:@"screen_height_pixels"]; - [deviceData setValue:@(appScreen.bounds.size.width) forKey:@"screen_width_pixels"]; - } + + NSArray *appWindows = SentryDependencyContainer.sharedInstance.application.windows; + if ([appWindows count] > 0) { + UIScreen *appScreen = appWindows.firstObject.screen; + if (appScreen != nil) { + [deviceData setValue:@(appScreen.bounds.size.height) forKey:@"screen_height_pixels"]; + [deviceData setValue:@(appScreen.bounds.size.width) forKey:@"screen_width_pixels"]; } - }]; + } + #endif [scope setContextValue:deviceData forKey:DEVICE_KEY]; From 95ab17a0f41263f44aeaa8b4dbe29b7d58002d9f Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Tue, 19 Sep 2023 16:32:53 +0200 Subject: [PATCH 03/38] Update SentrySDK.m --- Sources/Sentry/SentrySDK.m | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index 8ea1e0d2807..463b576b360 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -14,6 +14,8 @@ #import "SentryMeta.h" #import "SentryOptions+Private.h" #import "SentryScope.h" +#import "SentryDispatchQueueWrapper.h" + @interface SentrySDK () @@ -134,24 +136,26 @@ + (void)setStartInvocations:(NSUInteger)value + (void)startWithOptions:(SentryOptions *)options { - startInvocations++; + [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchSyncOnMainQueue:^{ + startInvocations++; - [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; + [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; - SentryClient *newClient = [[SentryClient alloc] initWithOptions:options]; - [newClient.fileManager moveAppStateToPreviousAppState]; - [newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs]; + SentryClient *newClient = [[SentryClient alloc] initWithOptions:options]; + [newClient.fileManager moveAppStateToPreviousAppState]; + [newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs]; - SentryScope *scope - = options.initialScope([[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]); - // The Hub needs to be initialized with a client so that closing a session - // can happen. - [SentrySDK setCurrentHub:[[SentryHub alloc] initWithClient:newClient andScope:scope]]; - SENTRY_LOG_DEBUG(@"SDK initialized! Version: %@", SentryMeta.versionString); - [SentrySDK installIntegrations]; + SentryScope *scope + = options.initialScope([[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]); + // The Hub needs to be initialized with a client so that closing a session + // can happen. + [SentrySDK setCurrentHub:[[SentryHub alloc] initWithClient:newClient andScope:scope]]; + SENTRY_LOG_DEBUG(@"SDK initialized! Version: %@", SentryMeta.versionString); + [SentrySDK installIntegrations]; - [SentryCrashWrapper.sharedInstance startBinaryImageCache]; - [SentryDependencyContainer.sharedInstance.binaryImageCache start]; + [SentryCrashWrapper.sharedInstance startBinaryImageCache]; + [SentryDependencyContainer.sharedInstance.binaryImageCache start]; + }]; } + (void)startWithConfigureOptions:(void (^)(SentryOptions *options))configureOptions From 5a9e4ea9b94493d26aafa5f9472e9f0062fd748d Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Tue, 19 Sep 2023 17:04:20 +0200 Subject: [PATCH 04/38] tests --- Sentry.xcodeproj/project.pbxproj | 4 ++++ SentryTestUtils/MainThreadTestIntegration.swift | 16 ++++++++++++++++ Tests/SentryTests/SentrySDKTests.swift | 16 +++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 SentryTestUtils/MainThreadTestIntegration.swift diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index 9674588648d..beb68a5b867 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -776,6 +776,7 @@ D86F419827C8FEFA00490520 /* SentryCoreDataTrackerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D86F419727C8FEFA00490520 /* SentryCoreDataTrackerExtension.swift */; }; D8751FA5274743710032F4DE /* SentryNSURLSessionTaskSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8751FA4274743710032F4DE /* SentryNSURLSessionTaskSearchTests.swift */; }; D875ED0B276CC84700422FAC /* SentryNSDataTrackerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D875ED0A276CC84700422FAC /* SentryNSDataTrackerTests.swift */; }; + D87FA2892AB9EB06007DE933 /* MainThreadTestIntegration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D87FA2882AB9EB06007DE933 /* MainThreadTestIntegration.swift */; }; D880E3A728573E87008A90DB /* SentryBaggageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D880E3A628573E87008A90DB /* SentryBaggageTests.swift */; }; D884A20527C80F6300074664 /* SentryCoreDataTrackerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = D884A20327C80F2700074664 /* SentryCoreDataTrackerTest.swift */; }; D885266427739D01001269FC /* SentryFileIOTrackingIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D885266327739D01001269FC /* SentryFileIOTrackingIntegrationTests.swift */; }; @@ -1727,6 +1728,7 @@ D8751FA4274743710032F4DE /* SentryNSURLSessionTaskSearchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSURLSessionTaskSearchTests.swift; sourceTree = ""; }; D8757D142A209F7300BFEFCC /* SentrySampleDecision+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentrySampleDecision+Private.h"; path = "include/SentrySampleDecision+Private.h"; sourceTree = ""; }; D875ED0A276CC84700422FAC /* SentryNSDataTrackerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SentryNSDataTrackerTests.swift; sourceTree = ""; }; + D87FA2882AB9EB06007DE933 /* MainThreadTestIntegration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainThreadTestIntegration.swift; sourceTree = ""; }; D880E3A628573E87008A90DB /* SentryBaggageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryBaggageTests.swift; sourceTree = ""; }; D880E3B02860A5A0008A90DB /* SentryEvent+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryEvent+Private.h"; path = "include/SentryEvent+Private.h"; sourceTree = ""; }; D884A20327C80F2700074664 /* SentryCoreDataTrackerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCoreDataTrackerTest.swift; sourceTree = ""; }; @@ -3180,6 +3182,7 @@ 84281C4D2A579A0C00EE88F2 /* SentryProfilerMocksSwiftCompatible.mm */, 84AC61DA29F7654A009EEF61 /* TestDispatchSourceWrapper.swift */, 84A5D75A29D5170700388BFA /* TimeInterval+Sentry.swift */, + D87FA2882AB9EB06007DE933 /* MainThreadTestIntegration.swift */, 7B30B68126527C55006B2752 /* TestDisplayLinkWrapper.swift */, 8E25C97425F8511A00DC215B /* TestRandom.swift */, 7BE3C7762445E50A00A38442 /* TestCurrentDateProvider.swift */, @@ -4482,6 +4485,7 @@ 84B7FA4529B2926900AD93B1 /* TestDisplayLinkWrapper.swift in Sources */, 84AC61DB29F7654A009EEF61 /* TestDispatchSourceWrapper.swift in Sources */, 8431F01729B2851500D8DC56 /* TestSentrySystemWrapper.swift in Sources */, + D87FA2892AB9EB06007DE933 /* MainThreadTestIntegration.swift in Sources */, 84281C632A579D0700EE88F2 /* SentryProfilerMocks.mm in Sources */, 84B7FA4129B28CD200AD93B1 /* TestSentryDispatchQueueWrapper.swift in Sources */, 84B7FA3E29B28ADD00AD93B1 /* TestClient.swift in Sources */, diff --git a/SentryTestUtils/MainThreadTestIntegration.swift b/SentryTestUtils/MainThreadTestIntegration.swift new file mode 100644 index 00000000000..5e1b1ce626a --- /dev/null +++ b/SentryTestUtils/MainThreadTestIntegration.swift @@ -0,0 +1,16 @@ +import Foundation +import Sentry + +public class MainThreadTestIntegration : NSObject, SentryIntegrationProtocol { + + public var installedInTheMainThread = false + + public func install(with options: Options) -> Bool { + installedInTheMainThread = Thread.isMainThread + return true + } + + public static func replaceOptionIntegrations(_ options: Options) { + options.integrations = [ NSStringFromClass(MainThreadTestIntegration.self) ] + } +} diff --git a/Tests/SentryTests/SentrySDKTests.swift b/Tests/SentryTests/SentrySDKTests.swift index 8df6ea9a106..49ee9b5882a 100644 --- a/Tests/SentryTests/SentrySDKTests.swift +++ b/Tests/SentryTests/SentrySDKTests.swift @@ -636,7 +636,21 @@ class SentrySDKTests: XCTestCase { XCTAssertEqual(flushTimeout, transport.flushInvocations.first) } - + + func testStartInTheMainThread() { + let expect = expectation(description: "SDK Initialization") + DispatchQueue.global(qos: .background).async { + SentrySDK.start { options in + MainThreadTestIntegration.replaceOptionIntegrations(options) + } + expect.fulfill() + } + wait(for: [expect], timeout: 0.2) + + let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first as? MainThreadTestIntegration + XCTAssertEqual(mainThreadIntegration?.installedInTheMainThread, true, "SDK is not being initialized in the main thread") + } + #if SENTRY_HAS_UIKIT func testSetAppStartMeasurementConcurrently() { From f0b432fdae11f4f4f3b10b45ab190b7c87543912 Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Tue, 19 Sep 2023 17:05:05 +0200 Subject: [PATCH 05/38] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5f954b2cbe..a314e4c6824 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- Start SDK only in the main thread (#3291) + ## 8.12.0 ### Fixes From 4fa8e1f227d5a00b7c690798edd19e9d0ba7c6c0 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Tue, 19 Sep 2023 15:05:44 +0000 Subject: [PATCH 06/38] Format code --- SentryTestUtils/MainThreadTestIntegration.swift | 2 +- Sources/Sentry/SentrySDK.m | 7 +++---- .../Recording/Tools/SentryCrashObjCApple.h | 6 +++--- Tests/SentryTests/SentryOptionsTest.m | 12 ++++-------- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/SentryTestUtils/MainThreadTestIntegration.swift b/SentryTestUtils/MainThreadTestIntegration.swift index 5e1b1ce626a..cdf5c572577 100644 --- a/SentryTestUtils/MainThreadTestIntegration.swift +++ b/SentryTestUtils/MainThreadTestIntegration.swift @@ -1,7 +1,7 @@ import Foundation import Sentry -public class MainThreadTestIntegration : NSObject, SentryIntegrationProtocol { +public class MainThreadTestIntegration: NSObject, SentryIntegrationProtocol { public var installedInTheMainThread = false diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index 463b576b360..27999a9ae28 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -8,14 +8,13 @@ #import "SentryCrash.h" #import "SentryCrashWrapper.h" #import "SentryDependencyContainer.h" +#import "SentryDispatchQueueWrapper.h" #import "SentryFileManager.h" #import "SentryHub+Private.h" #import "SentryLog.h" #import "SentryMeta.h" #import "SentryOptions+Private.h" #import "SentryScope.h" -#import "SentryDispatchQueueWrapper.h" - @interface SentrySDK () @@ -145,8 +144,8 @@ + (void)startWithOptions:(SentryOptions *)options [newClient.fileManager moveAppStateToPreviousAppState]; [newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs]; - SentryScope *scope - = options.initialScope([[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]); + SentryScope *scope = options.initialScope( + [[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]); // The Hub needs to be initialized with a client so that closing a session // can happen. [SentrySDK setCurrentHub:[[SentryHub alloc] initWithClient:newClient andScope:scope]]; diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h index 441c108dd1f..c665cdf51c4 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h @@ -288,8 +288,8 @@ typedef struct __CFRuntimeBase { # define __CF_BIG_ENDIAN__ 0 #endif -#define CF_INFO_BITS (!!(__CF_BIG_ENDIAN__)*3) -#define CF_RC_BITS (!!(__CF_LITTLE_ENDIAN__)*3) +#define CF_INFO_BITS (!!(__CF_BIG_ENDIAN__) * 3) +#define CF_RC_BITS (!!(__CF_LITTLE_ENDIAN__) * 3) /* Bit manipulation macros */ /* Bits are numbered from 31 on left to 0 on right */ @@ -299,7 +299,7 @@ typedef struct __CFRuntimeBase { /* In the following, N1 and N2 specify an inclusive range N2..N1 with N1 >= N2 */ #define __CFBitfieldMask(N1, N2) ((((UInt32)~0UL) << (31UL - (N1) + (N2))) >> (31UL - N1)) -#define __CFBitfieldGetValue(V, N1, N2) (((V)&__CFBitfieldMask(N1, N2)) >> (N2)) +#define __CFBitfieldGetValue(V, N1, N2) (((V) & __CFBitfieldMask(N1, N2)) >> (N2)) // ====================================================================== #pragma mark - CF-1153.18/CFString.c - diff --git a/Tests/SentryTests/SentryOptionsTest.m b/Tests/SentryTests/SentryOptionsTest.m index 2fa263f2e0e..f22a91dc3dd 100644 --- a/Tests/SentryTests/SentryOptionsTest.m +++ b/Tests/SentryTests/SentryOptionsTest.m @@ -801,10 +801,8 @@ - (void)testChanging_enableTracing_afterSetting_tracesSampleRate - (void)testChanging_enableTracing_afterSetting_tracesSampler { SentryOptions *options = [[SentryOptions alloc] init]; - options.tracesSampler = ^NSNumber *(SentrySamplingContext *__unused samplingContext) - { - return @0.1; - }; + options.tracesSampler + = ^NSNumber *(SentrySamplingContext *__unused samplingContext) { return @0.1; }; options.enableTracing = NO; XCTAssertNil(options.tracesSampleRate); options.enableTracing = FALSE; @@ -1161,10 +1159,8 @@ - (void)testDefaultInitialScope - (void)testInitialScope { - SentryScope * (^initialScope)(SentryScope *) = ^SentryScope *(SentryScope *scope) - { - return scope; - }; + SentryScope * (^initialScope)(SentryScope *) + = ^SentryScope *(SentryScope *scope) { return scope; }; SentryOptions *options = [self getValidOptions:@{ @"initialScope" : initialScope }]; XCTAssertIdentical(initialScope, options.initialScope); } From 6ee2b675e12f87f40473508503df51da38be92f1 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Wed, 20 Sep 2023 09:22:37 +0200 Subject: [PATCH 07/38] Update Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h --- Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h index c665cdf51c4..0942f5dd411 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h @@ -288,8 +288,8 @@ typedef struct __CFRuntimeBase { # define __CF_BIG_ENDIAN__ 0 #endif -#define CF_INFO_BITS (!!(__CF_BIG_ENDIAN__) * 3) -#define CF_RC_BITS (!!(__CF_LITTLE_ENDIAN__) * 3) +#define CF_INFO_BITS (!!(__CF_BIG_ENDIAN__)*3) +#define CF_RC_BITS (!!(__CF_LITTLE_ENDIAN__)*3) /* Bit manipulation macros */ /* Bits are numbered from 31 on left to 0 on right */ From 490ed4f97a2e1a022132ec5cdf2115b0af91b63a Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Wed, 20 Sep 2023 07:23:27 +0000 Subject: [PATCH 08/38] Format code --- Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h index 0942f5dd411..c665cdf51c4 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h @@ -288,8 +288,8 @@ typedef struct __CFRuntimeBase { # define __CF_BIG_ENDIAN__ 0 #endif -#define CF_INFO_BITS (!!(__CF_BIG_ENDIAN__)*3) -#define CF_RC_BITS (!!(__CF_LITTLE_ENDIAN__)*3) +#define CF_INFO_BITS (!!(__CF_BIG_ENDIAN__) * 3) +#define CF_RC_BITS (!!(__CF_LITTLE_ENDIAN__) * 3) /* Bit manipulation macros */ /* Bits are numbered from 31 on left to 0 on right */ From 3ffba00d273ff9afd1a08a68bbf970e03c05265a Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Wed, 20 Sep 2023 09:25:38 +0200 Subject: [PATCH 09/38] Apply suggestions from code review --- .../Recording/Tools/SentryCrashObjCApple.h | 2 +- Tests/SentryTests/SentryOptionsTest.m | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h index c665cdf51c4..b14dd7ff220 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h @@ -299,7 +299,7 @@ typedef struct __CFRuntimeBase { /* In the following, N1 and N2 specify an inclusive range N2..N1 with N1 >= N2 */ #define __CFBitfieldMask(N1, N2) ((((UInt32)~0UL) << (31UL - (N1) + (N2))) >> (31UL - N1)) -#define __CFBitfieldGetValue(V, N1, N2) (((V) & __CFBitfieldMask(N1, N2)) >> (N2)) +#define __CFBitfieldGetValue(V, N1, N2) (((V)&__CFBitfieldMask(N1, N2)) >> (N2)) // ====================================================================== #pragma mark - CF-1153.18/CFString.c - diff --git a/Tests/SentryTests/SentryOptionsTest.m b/Tests/SentryTests/SentryOptionsTest.m index f22a91dc3dd..46eb6206327 100644 --- a/Tests/SentryTests/SentryOptionsTest.m +++ b/Tests/SentryTests/SentryOptionsTest.m @@ -801,8 +801,10 @@ - (void)testChanging_enableTracing_afterSetting_tracesSampleRate - (void)testChanging_enableTracing_afterSetting_tracesSampler { SentryOptions *options = [[SentryOptions alloc] init]; - options.tracesSampler - = ^NSNumber *(SentrySamplingContext *__unused samplingContext) { return @0.1; }; + options.tracesSampler = ^NSNumber *(SentrySamplingContext *__unused samplingContext) + { + return @0.1; + }; options.enableTracing = NO; XCTAssertNil(options.tracesSampleRate); options.enableTracing = FALSE; @@ -1159,8 +1161,10 @@ - (void)testDefaultInitialScope - (void)testInitialScope { - SentryScope * (^initialScope)(SentryScope *) - = ^SentryScope *(SentryScope *scope) { return scope; }; + SentryScope * (^initialScope)(SentryScope *) = ^SentryScope *(SentryScope *scope) + { + return scope; + }; SentryOptions *options = [self getValidOptions:@{ @"initialScope" : initialScope }]; XCTAssertIdentical(initialScope, options.initialScope); } From af5a3e5072352a7db9923dcec1a3e88d5b5d5af6 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Wed, 20 Sep 2023 07:27:24 +0000 Subject: [PATCH 10/38] Format code --- .../Recording/Tools/SentryCrashObjCApple.h | 2 +- Tests/SentryTests/SentryOptionsTest.m | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h index b14dd7ff220..c665cdf51c4 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h @@ -299,7 +299,7 @@ typedef struct __CFRuntimeBase { /* In the following, N1 and N2 specify an inclusive range N2..N1 with N1 >= N2 */ #define __CFBitfieldMask(N1, N2) ((((UInt32)~0UL) << (31UL - (N1) + (N2))) >> (31UL - N1)) -#define __CFBitfieldGetValue(V, N1, N2) (((V)&__CFBitfieldMask(N1, N2)) >> (N2)) +#define __CFBitfieldGetValue(V, N1, N2) (((V) & __CFBitfieldMask(N1, N2)) >> (N2)) // ====================================================================== #pragma mark - CF-1153.18/CFString.c - diff --git a/Tests/SentryTests/SentryOptionsTest.m b/Tests/SentryTests/SentryOptionsTest.m index 46eb6206327..f22a91dc3dd 100644 --- a/Tests/SentryTests/SentryOptionsTest.m +++ b/Tests/SentryTests/SentryOptionsTest.m @@ -801,10 +801,8 @@ - (void)testChanging_enableTracing_afterSetting_tracesSampleRate - (void)testChanging_enableTracing_afterSetting_tracesSampler { SentryOptions *options = [[SentryOptions alloc] init]; - options.tracesSampler = ^NSNumber *(SentrySamplingContext *__unused samplingContext) - { - return @0.1; - }; + options.tracesSampler + = ^NSNumber *(SentrySamplingContext *__unused samplingContext) { return @0.1; }; options.enableTracing = NO; XCTAssertNil(options.tracesSampleRate); options.enableTracing = FALSE; @@ -1161,10 +1159,8 @@ - (void)testDefaultInitialScope - (void)testInitialScope { - SentryScope * (^initialScope)(SentryScope *) = ^SentryScope *(SentryScope *scope) - { - return scope; - }; + SentryScope * (^initialScope)(SentryScope *) + = ^SentryScope *(SentryScope *scope) { return scope; }; SentryOptions *options = [self getValidOptions:@{ @"initialScope" : initialScope }]; XCTAssertIdentical(initialScope, options.initialScope); } From 26f8b497ed78aad7b33bc6a65c2c4d6a39b33309 Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Wed, 20 Sep 2023 11:25:07 +0200 Subject: [PATCH 11/38] Update SentrySDK.m --- Sources/Sentry/SentrySDK.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index 27999a9ae28..0e4369ddd74 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -135,7 +135,7 @@ + (void)setStartInvocations:(NSUInteger)value + (void)startWithOptions:(SentryOptions *)options { - [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchSyncOnMainQueue:^{ + void (^startSDK)(void) = ^{ startInvocations++; [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; @@ -154,7 +154,13 @@ + (void)startWithOptions:(SentryOptions *)options [SentryCrashWrapper.sharedInstance startBinaryImageCache]; [SentryDependencyContainer.sharedInstance.binaryImageCache start]; - }]; + }; + + if (NSThread.isMainThread) { + startSDK(); + } else { + [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchAsyncOnMainQueue:startSDK]; + } } + (void)startWithConfigureOptions:(void (^)(SentryOptions *options))configureOptions From b87e505854d061172e0f47b0704bfaf629fd4346 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Wed, 20 Sep 2023 09:26:33 +0000 Subject: [PATCH 12/38] Format code --- Sources/Sentry/SentrySDK.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index 0e4369ddd74..d3f794566f1 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -159,7 +159,8 @@ + (void)startWithOptions:(SentryOptions *)options if (NSThread.isMainThread) { startSDK(); } else { - [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchAsyncOnMainQueue:startSDK]; + [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper + dispatchAsyncOnMainQueue:startSDK]; } } From 673d34ca52e5db8ac199d05d3658b156cb672d6a Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Wed, 20 Sep 2023 13:21:49 +0200 Subject: [PATCH 13/38] Update SentrySDKTests.swift --- Tests/SentryTests/SentrySDKTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SentryTests/SentrySDKTests.swift b/Tests/SentryTests/SentrySDKTests.swift index 49ee9b5882a..ff87efd1730 100644 --- a/Tests/SentryTests/SentrySDKTests.swift +++ b/Tests/SentryTests/SentrySDKTests.swift @@ -645,7 +645,7 @@ class SentrySDKTests: XCTestCase { } expect.fulfill() } - wait(for: [expect], timeout: 0.2) + wait(for: [expect], timeout: 0.5) let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first as? MainThreadTestIntegration XCTAssertEqual(mainThreadIntegration?.installedInTheMainThread, true, "SDK is not being initialized in the main thread") From 5791da48913b1fd238336064442a786f0539db73 Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Thu, 21 Sep 2023 10:53:19 +0200 Subject: [PATCH 14/38] Update SentrySDK.m --- Sources/Sentry/SentrySDK.m | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index d3f794566f1..bc7af5c3251 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -15,6 +15,7 @@ #import "SentryMeta.h" #import "SentryOptions+Private.h" #import "SentryScope.h" +#import "SentryThreadWrapper.h" @interface SentrySDK () @@ -135,7 +136,7 @@ + (void)setStartInvocations:(NSUInteger)value + (void)startWithOptions:(SentryOptions *)options { - void (^startSDK)(void) = ^{ + [SentryThreadWrapper onMainThread:^{ startInvocations++; [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; @@ -154,14 +155,7 @@ + (void)startWithOptions:(SentryOptions *)options [SentryCrashWrapper.sharedInstance startBinaryImageCache]; [SentryDependencyContainer.sharedInstance.binaryImageCache start]; - }; - - if (NSThread.isMainThread) { - startSDK(); - } else { - [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper - dispatchAsyncOnMainQueue:startSDK]; - } + }]; } + (void)startWithConfigureOptions:(void (^)(SentryOptions *options))configureOptions From b96bc4ba1c0cd217f75466ecfe77e094ea064ca5 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Mon, 25 Sep 2023 08:05:49 +0000 Subject: [PATCH 15/38] Format code --- Sources/Sentry/SentrySDK.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index 28785a6db99..cf56d4fd2bc 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -156,9 +156,9 @@ + (void)startWithOptions:(SentryOptions *)options [SentryCrashWrapper.sharedInstance startBinaryImageCache]; [SentryDependencyContainer.sharedInstance.binaryImageCache start]; - #if TARGET_OS_IOS +#if TARGET_OS_IOS [SentryDependencyContainer.sharedInstance.uiDeviceWrapper start]; - #endif +#endif }]; } From 73db55650a9a3d70757f373a06f9ce68ca27ca7d Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Thu, 28 Sep 2023 13:54:36 +0200 Subject: [PATCH 16/38] Update SentrySDKTests.swift --- Tests/SentryTests/SentrySDKTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SentryTests/SentrySDKTests.swift b/Tests/SentryTests/SentrySDKTests.swift index 32b79acc2ba..080dc1afd4c 100644 --- a/Tests/SentryTests/SentrySDKTests.swift +++ b/Tests/SentryTests/SentrySDKTests.swift @@ -664,7 +664,7 @@ class SentrySDKTests: XCTestCase { } wait(for: [expect], timeout: 0.5) - let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first as? MainThreadTestIntegration + let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first { integration in integration is MainThreadTestIntegration } as? MainThreadTestIntegration XCTAssertEqual(mainThreadIntegration?.installedInTheMainThread, true, "SDK is not being initialized in the main thread") } From 45b181b76f9d68a0160375e187014a10a386a7fc Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Thu, 28 Sep 2023 14:04:03 +0200 Subject: [PATCH 17/38] Update SentrySDK.m --- Sources/Sentry/SentrySDK.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index cf56d4fd2bc..f8720e8d37f 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -137,7 +137,7 @@ + (void)setStartInvocations:(NSUInteger)value + (void)startWithOptions:(SentryOptions *)options { - [SentryThreadWrapper onMainThread:^{ + // [SentryThreadWrapper onMainThread:^{ startInvocations++; [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; @@ -159,7 +159,7 @@ + (void)startWithOptions:(SentryOptions *)options #if TARGET_OS_IOS [SentryDependencyContainer.sharedInstance.uiDeviceWrapper start]; #endif - }]; +// }]; } + (void)startWithConfigureOptions:(void (^)(SentryOptions *options))configureOptions From cd29f40d63f412595d19f5b58406e514850aa244 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 28 Sep 2023 12:05:04 +0000 Subject: [PATCH 18/38] Format code --- Sources/Sentry/SentrySDK.m | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index f8720e8d37f..64f02aa0cd9 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -137,29 +137,29 @@ + (void)setStartInvocations:(NSUInteger)value + (void)startWithOptions:(SentryOptions *)options { - // [SentryThreadWrapper onMainThread:^{ - startInvocations++; + // [SentryThreadWrapper onMainThread:^{ + startInvocations++; - [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; + [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; - SentryClient *newClient = [[SentryClient alloc] initWithOptions:options]; - [newClient.fileManager moveAppStateToPreviousAppState]; - [newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs]; + SentryClient *newClient = [[SentryClient alloc] initWithOptions:options]; + [newClient.fileManager moveAppStateToPreviousAppState]; + [newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs]; - SentryScope *scope = options.initialScope( - [[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]); - // The Hub needs to be initialized with a client so that closing a session - // can happen. - [SentrySDK setCurrentHub:[[SentryHub alloc] initWithClient:newClient andScope:scope]]; - SENTRY_LOG_DEBUG(@"SDK initialized! Version: %@", SentryMeta.versionString); - [SentrySDK installIntegrations]; + SentryScope *scope + = options.initialScope([[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]); + // The Hub needs to be initialized with a client so that closing a session + // can happen. + [SentrySDK setCurrentHub:[[SentryHub alloc] initWithClient:newClient andScope:scope]]; + SENTRY_LOG_DEBUG(@"SDK initialized! Version: %@", SentryMeta.versionString); + [SentrySDK installIntegrations]; - [SentryCrashWrapper.sharedInstance startBinaryImageCache]; - [SentryDependencyContainer.sharedInstance.binaryImageCache start]; + [SentryCrashWrapper.sharedInstance startBinaryImageCache]; + [SentryDependencyContainer.sharedInstance.binaryImageCache start]; #if TARGET_OS_IOS - [SentryDependencyContainer.sharedInstance.uiDeviceWrapper start]; + [SentryDependencyContainer.sharedInstance.uiDeviceWrapper start]; #endif -// }]; + // }]; } + (void)startWithConfigureOptions:(void (^)(SentryOptions *options))configureOptions From fb5eebcb521704f340b44cc5a4867a914fc9b02b Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Thu, 28 Sep 2023 14:17:39 +0200 Subject: [PATCH 19/38] Update SentrySDKTests.swift --- Tests/SentryTests/SentrySDKTests.swift | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Tests/SentryTests/SentrySDKTests.swift b/Tests/SentryTests/SentrySDKTests.swift index 080dc1afd4c..469cae0bcc6 100644 --- a/Tests/SentryTests/SentrySDKTests.swift +++ b/Tests/SentryTests/SentrySDKTests.swift @@ -654,19 +654,19 @@ class SentrySDKTests: XCTestCase { XCTAssertEqual(flushTimeout, transport.flushInvocations.first) } - func testStartInTheMainThread() { - let expect = expectation(description: "SDK Initialization") - DispatchQueue.global(qos: .background).async { - SentrySDK.start { options in - MainThreadTestIntegration.replaceOptionIntegrations(options) - } - expect.fulfill() - } - wait(for: [expect], timeout: 0.5) - - let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first { integration in integration is MainThreadTestIntegration } as? MainThreadTestIntegration - XCTAssertEqual(mainThreadIntegration?.installedInTheMainThread, true, "SDK is not being initialized in the main thread") - } +// func testStartInTheMainThread() { +// let expect = expectation(description: "SDK Initialization") +// DispatchQueue.global(qos: .background).async { +// SentrySDK.start { options in +// MainThreadTestIntegration.replaceOptionIntegrations(options) +// } +// expect.fulfill() +// } +// wait(for: [expect], timeout: 0.5) +// +// let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first { integration in integration is MainThreadTestIntegration } as? MainThreadTestIntegration +// XCTAssertEqual(mainThreadIntegration?.installedInTheMainThread, true, "SDK is not being initialized in the main thread") +// } #if SENTRY_HAS_UIKIT From e6825295a6a5587a008c1dad3b3a92e0d7661121 Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Thu, 28 Sep 2023 15:40:46 +0200 Subject: [PATCH 20/38] Fix Reachability flackness --- Sources/Sentry/SentryReachability.m | 6 ++++++ Tests/SentryTests/Networking/SentryReachabilityTests.m | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/Sources/Sentry/SentryReachability.m b/Sources/Sentry/SentryReachability.m index 3af2292bc13..146f8790ab1 100644 --- a/Sources/Sentry/SentryReachability.m +++ b/Sources/Sentry/SentryReachability.m @@ -98,6 +98,12 @@ } } +void +SentryConnectivityReset(void) { + [sentry_reachability_change_blocks removeAllObjects]; + sentry_current_reachability_state = kSCNetworkReachabilityFlagsUninitialized; +} + @implementation SentryReachability + (void)initialize diff --git a/Tests/SentryTests/Networking/SentryReachabilityTests.m b/Tests/SentryTests/Networking/SentryReachabilityTests.m index bf733289d0a..43324bd1f93 100644 --- a/Tests/SentryTests/Networking/SentryReachabilityTests.m +++ b/Tests/SentryTests/Networking/SentryReachabilityTests.m @@ -2,6 +2,9 @@ #import "SentryReachability.h" #import +void +SentryConnectivityReset(void); + @interface TestSentryReachabilityObserver : NSObject @end @implementation TestSentryReachabilityObserver @@ -22,6 +25,7 @@ - (void)setUp - (void)tearDown { self.reachability = nil; + SentryConnectivityReset(); } - (void)testConnectivityRepresentations From 262c625780e52a807f6ceb65cce82aaeded167d5 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 28 Sep 2023 13:42:20 +0000 Subject: [PATCH 21/38] Format code --- Sources/Sentry/SentryReachability.m | 3 ++- Tests/SentryTests/Networking/SentryReachabilityTests.m | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Sentry/SentryReachability.m b/Sources/Sentry/SentryReachability.m index 146f8790ab1..6eae307a444 100644 --- a/Sources/Sentry/SentryReachability.m +++ b/Sources/Sentry/SentryReachability.m @@ -99,7 +99,8 @@ } void -SentryConnectivityReset(void) { +SentryConnectivityReset(void) +{ [sentry_reachability_change_blocks removeAllObjects]; sentry_current_reachability_state = kSCNetworkReachabilityFlagsUninitialized; } diff --git a/Tests/SentryTests/Networking/SentryReachabilityTests.m b/Tests/SentryTests/Networking/SentryReachabilityTests.m index 43324bd1f93..5e729343127 100644 --- a/Tests/SentryTests/Networking/SentryReachabilityTests.m +++ b/Tests/SentryTests/Networking/SentryReachabilityTests.m @@ -2,8 +2,7 @@ #import "SentryReachability.h" #import -void -SentryConnectivityReset(void); +void SentryConnectivityReset(void); @interface TestSentryReachabilityObserver : NSObject @end From d41ebfc61e6e3bb8e5361afa041e37b9e4971e3b Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Thu, 28 Sep 2023 16:30:01 +0200 Subject: [PATCH 22/38] Update SentrySDK.m --- Sources/Sentry/SentrySDK.m | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index 64f02aa0cd9..855738616fe 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -137,29 +137,29 @@ + (void)setStartInvocations:(NSUInteger)value + (void)startWithOptions:(SentryOptions *)options { - // [SentryThreadWrapper onMainThread:^{ - startInvocations++; - - [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; - - SentryClient *newClient = [[SentryClient alloc] initWithOptions:options]; - [newClient.fileManager moveAppStateToPreviousAppState]; - [newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs]; - - SentryScope *scope + [SentryThreadWrapper onMainThread:^{ + startInvocations++; + + [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; + + SentryClient *newClient = [[SentryClient alloc] initWithOptions:options]; + [newClient.fileManager moveAppStateToPreviousAppState]; + [newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs]; + + SentryScope *scope = options.initialScope([[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]); - // The Hub needs to be initialized with a client so that closing a session - // can happen. - [SentrySDK setCurrentHub:[[SentryHub alloc] initWithClient:newClient andScope:scope]]; - SENTRY_LOG_DEBUG(@"SDK initialized! Version: %@", SentryMeta.versionString); - [SentrySDK installIntegrations]; - - [SentryCrashWrapper.sharedInstance startBinaryImageCache]; - [SentryDependencyContainer.sharedInstance.binaryImageCache start]; + // The Hub needs to be initialized with a client so that closing a session + // can happen. + [SentrySDK setCurrentHub:[[SentryHub alloc] initWithClient:newClient andScope:scope]]; + SENTRY_LOG_DEBUG(@"SDK initialized! Version: %@", SentryMeta.versionString); + [SentrySDK installIntegrations]; + + [SentryCrashWrapper.sharedInstance startBinaryImageCache]; + [SentryDependencyContainer.sharedInstance.binaryImageCache start]; #if TARGET_OS_IOS - [SentryDependencyContainer.sharedInstance.uiDeviceWrapper start]; + [SentryDependencyContainer.sharedInstance.uiDeviceWrapper start]; #endif - // }]; + }]; } + (void)startWithConfigureOptions:(void (^)(SentryOptions *options))configureOptions From 3194c1d582b74bfc5c7182a8fbf164752018771f Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 28 Sep 2023 14:34:08 +0000 Subject: [PATCH 23/38] Format code --- Sources/Sentry/SentrySDK.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index 855738616fe..cf56d4fd2bc 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -139,21 +139,21 @@ + (void)startWithOptions:(SentryOptions *)options { [SentryThreadWrapper onMainThread:^{ startInvocations++; - + [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; - + SentryClient *newClient = [[SentryClient alloc] initWithOptions:options]; [newClient.fileManager moveAppStateToPreviousAppState]; [newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs]; - - SentryScope *scope - = options.initialScope([[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]); + + SentryScope *scope = options.initialScope( + [[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]); // The Hub needs to be initialized with a client so that closing a session // can happen. [SentrySDK setCurrentHub:[[SentryHub alloc] initWithClient:newClient andScope:scope]]; SENTRY_LOG_DEBUG(@"SDK initialized! Version: %@", SentryMeta.versionString); [SentrySDK installIntegrations]; - + [SentryCrashWrapper.sharedInstance startBinaryImageCache]; [SentryDependencyContainer.sharedInstance.binaryImageCache start]; #if TARGET_OS_IOS From 6692ff983d9196e4309f0fae553224b484fa5117 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Wed, 4 Oct 2023 16:16:23 +0200 Subject: [PATCH 24/38] Update SentryReachability.m --- Sources/Sentry/SentryReachability.m | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/Sentry/SentryReachability.m b/Sources/Sentry/SentryReachability.m index db561cc0cb5..a2d8573d0f8 100644 --- a/Sources/Sentry/SentryReachability.m +++ b/Sources/Sentry/SentryReachability.m @@ -116,9 +116,8 @@ + (void)initialize - (void)dealloc { - for (id observer in sentry_reachability_change_blocks.allKeys) { - [self removeObserver:observer]; - } + sentry_reachability_change_blocks = [NSMutableDictionary dictionary]; + [self removeReachabilityNotification]; } - (void)addObserver:(id)observer @@ -154,6 +153,10 @@ - (void)removeObserver:(id)observer return; } + [self removeReachabilityNotification]; +} + +- (void)removeReachabilityNotification { sentry_current_reachability_state = kSCNetworkReachabilityFlagsUninitialized; if (_sentry_reachability_ref == nil) { From aedd343ade7641121cb1080cf5b09e540a5e383d Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Wed, 4 Oct 2023 15:18:52 +0000 Subject: [PATCH 25/38] Format code --- Sources/Sentry/SentryReachability.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Sentry/SentryReachability.m b/Sources/Sentry/SentryReachability.m index a2d8573d0f8..7c1d3398284 100644 --- a/Sources/Sentry/SentryReachability.m +++ b/Sources/Sentry/SentryReachability.m @@ -156,7 +156,8 @@ - (void)removeObserver:(id)observer [self removeReachabilityNotification]; } -- (void)removeReachabilityNotification { +- (void)removeReachabilityNotification +{ sentry_current_reachability_state = kSCNetworkReachabilityFlagsUninitialized; if (_sentry_reachability_ref == nil) { From cc4d0e3780c76feaa71ca6f8272e1fea9f75b42f Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Thu, 5 Oct 2023 11:48:56 +0200 Subject: [PATCH 26/38] Update SentrySDKTests.swift --- Tests/SentryTests/SentrySDKTests.swift | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Tests/SentryTests/SentrySDKTests.swift b/Tests/SentryTests/SentrySDKTests.swift index 469cae0bcc6..080dc1afd4c 100644 --- a/Tests/SentryTests/SentrySDKTests.swift +++ b/Tests/SentryTests/SentrySDKTests.swift @@ -654,19 +654,19 @@ class SentrySDKTests: XCTestCase { XCTAssertEqual(flushTimeout, transport.flushInvocations.first) } -// func testStartInTheMainThread() { -// let expect = expectation(description: "SDK Initialization") -// DispatchQueue.global(qos: .background).async { -// SentrySDK.start { options in -// MainThreadTestIntegration.replaceOptionIntegrations(options) -// } -// expect.fulfill() -// } -// wait(for: [expect], timeout: 0.5) -// -// let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first { integration in integration is MainThreadTestIntegration } as? MainThreadTestIntegration -// XCTAssertEqual(mainThreadIntegration?.installedInTheMainThread, true, "SDK is not being initialized in the main thread") -// } + func testStartInTheMainThread() { + let expect = expectation(description: "SDK Initialization") + DispatchQueue.global(qos: .background).async { + SentrySDK.start { options in + MainThreadTestIntegration.replaceOptionIntegrations(options) + } + expect.fulfill() + } + wait(for: [expect], timeout: 0.5) + + let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first { integration in integration is MainThreadTestIntegration } as? MainThreadTestIntegration + XCTAssertEqual(mainThreadIntegration?.installedInTheMainThread, true, "SDK is not being initialized in the main thread") + } #if SENTRY_HAS_UIKIT From f58236a697357e69932904e150e24634fdfd27ae Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Wed, 11 Oct 2023 09:02:39 +0200 Subject: [PATCH 27/38] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcb21dad3eb..9de3177d787 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Fixes -- Start SDK only in the main thread (#3291) +- Start SDK on the main thread (#3291) - App hang with race condition for tick counter (#3290) - Remove "duplicate library" warning (#3312) From 33e5dbe59e6df1026ff23fd0fcbabc4a516d2e80 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Wed, 4 Oct 2023 19:23:14 +0200 Subject: [PATCH 28/38] ref: Replace deprecated function (#3327) Replaced macOS OS version retrieval from a deprecated API to a new one --- Sources/Sentry/SentryDevice.mm | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/Sources/Sentry/SentryDevice.mm b/Sources/Sentry/SentryDevice.mm index 86dcb14b35b..98b9cd15979 100644 --- a/Sources/Sentry/SentryDevice.mm +++ b/Sources/Sentry/SentryDevice.mm @@ -183,24 +183,9 @@ #elif SENTRY_HAS_UIKIT return UIDevice.currentDevice.systemVersion; #else - // based off of - // https://github.com/lmirosevic/GBDeviceInfo/blob/98dd3c75bb0e1f87f3e0fd909e52dcf0da4aa47d/GBDeviceInfo/GBDeviceInfo_OSX.m#L107-L133 - if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) { - const auto version = [[NSProcessInfo processInfo] operatingSystemVersion]; - return [NSString stringWithFormat:@"%ld.%ld.%ld", (long)version.majorVersion, - (long)version.minorVersion, (long)version.patchVersion]; - } else { - SInt32 major, minor, patch; - -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wdeprecated-declarations" - Gestalt(gestaltSystemVersionMajor, &major); - Gestalt(gestaltSystemVersionMinor, &minor); - Gestalt(gestaltSystemVersionBugFix, &patch); -# pragma clang diagnostic pop - - return [NSString stringWithFormat:@"%d.%d.%d", major, minor, patch]; - } + const auto version = [[NSProcessInfo processInfo] operatingSystemVersion]; + return [NSString stringWithFormat:@"%ld.%ld.%ld", (long)version.majorVersion, + (long)version.minorVersion, (long)version.patchVersion]; #endif // SENTRY_HAS_UIKIT } From 9bb1c590f8664ed09cb4f0b6931cb706ba1b354d Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Wed, 4 Oct 2023 14:41:20 -0700 Subject: [PATCH 29/38] ci: update unit test iOS/Xcode versions (#3283) Co-authored-by: Andrew McKnight --- .github/workflows/test.yml | 10 +++++++--- scripts/xcode-test.sh | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bd0f26ed8e2..89604977e9c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -84,24 +84,28 @@ jobs: platform: "iOS" xcode: "13.2.1" test-destination-os: "13.7" + device: "iPhone 8" # iOS 14 - runs-on: macos-11 platform: "iOS" xcode: "13.2.1" test-destination-os: "14.5" + device: "iPhone 8" # iOS 15 - runs-on: macos-12 platform: "iOS" xcode: "13.4.1" test-destination-os: "latest" + device: "iPhone 8" # iOS 16 - runs-on: macos-13 platform: "iOS" xcode: "14.3" - test-destination-os: "latest" + test-destination-os: "16.4" + device: "iPhone 14" # macOS 11 - runs-on: macos-11 @@ -178,14 +182,14 @@ jobs: # We split building and running tests in two steps so we know how long running the tests takes. - name: Build tests id: build_tests - run: ./scripts/xcode-test.sh ${{matrix.platform}} ${{matrix.test-destination-os}} $GITHUB_REF_NAME ci build-for-testing + run: ./scripts/xcode-test.sh ${{matrix.platform}} ${{matrix.test-destination-os}} $GITHUB_REF_NAME ci build-for-testing "${{matrix.device}}" - name: Run tests # We call a script with the platform so the destination # passed to xcodebuild doesn't end up in the job name, # because GitHub Actions don't provide an easy way of # manipulating string in expressions. - run: ./scripts/xcode-test.sh ${{matrix.platform}} ${{matrix.test-destination-os}} $GITHUB_REF_NAME ci test-without-building + run: ./scripts/xcode-test.sh ${{matrix.platform}} ${{matrix.test-destination-os}} $GITHUB_REF_NAME ci test-without-building "${{matrix.device}}" - name: Slowest Tests if: ${{ always() }} diff --git a/scripts/xcode-test.sh b/scripts/xcode-test.sh index aec74e25339..f10af433649 100755 --- a/scripts/xcode-test.sh +++ b/scripts/xcode-test.sh @@ -10,6 +10,7 @@ set -euxo pipefail PLATFORM="${1}" OS=${2:-latest} +DEVICE=${6:-iPhone 14} REF_NAME="${3-HEAD}" IS_LOCAL_BUILD="${4:-ci}" COMMAND="${5:-test}" @@ -27,7 +28,7 @@ case $PLATFORM in ;; "iOS") - DESTINATION="platform=iOS Simulator,OS=$OS,name=iPhone 8" + DESTINATION="platform=iOS Simulator,OS=$OS,name=$DEVICE" ;; "tvOS") From 4815a2f439f30b0327558cb37037a89422126ea1 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Thu, 5 Oct 2023 08:54:14 +0200 Subject: [PATCH 30/38] Fix: Remove unnecessaries build settings (#3325) This building settings were causing warning with Xcode 15 --- CHANGELOG.md | 1 + Sentry.xcodeproj/project.pbxproj | 12 ------------ Sources/Configuration/SDK.xcconfig | 5 ----- 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9de3177d787..0577237093b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Start SDK on the main thread (#3291) - App hang with race condition for tick counter (#3290) - Remove "duplicate library" warning (#3312) +- Remove unnecessaries build settings (#3325) ## 8.13.0 diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index d4de22255f8..28225f7a109 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -4701,7 +4701,6 @@ GCC_WARN_SHADOW = YES; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_DYLIB_INSTALL_NAME = "$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-DCARTHAGE_$(CARTHAGE)"; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry; @@ -4738,7 +4737,6 @@ GCC_WARN_SHADOW = YES; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_DYLIB_INSTALL_NAME = "$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-DCARTHAGE_$(CARTHAGE)"; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry; @@ -4891,7 +4889,6 @@ GCC_WARN_SHADOW = YES; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_DYLIB_INSTALL_NAME = "$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-DCARTHAGE_$(CARTHAGE)"; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry; @@ -5236,7 +5233,6 @@ GCC_WARN_SHADOW = YES; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_DYLIB_INSTALL_NAME = "$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-DCARTHAGE_$(CARTHAGE)"; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.Sentry; @@ -5299,7 +5295,6 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2022 Sentry. All rights reserved."; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MARKETING_VERSION = 1.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; @@ -5339,7 +5334,6 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2022 Sentry. All rights reserved."; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MARKETING_VERSION = 1.0; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.SentrySwiftUI; @@ -5376,7 +5370,6 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2022 Sentry. All rights reserved."; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MARKETING_VERSION = 1.0; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.SentrySwiftUI; @@ -5413,7 +5406,6 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2022 Sentry. All rights reserved."; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MARKETING_VERSION = 1.0; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.SentrySwiftUI; @@ -5446,7 +5438,6 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2022 Sentry. All rights reserved."; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.SentryPrivate; @@ -5479,7 +5470,6 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2022 Sentry. All rights reserved."; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.SentryPrivate; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -5509,7 +5499,6 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2022 Sentry. All rights reserved."; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.SentryPrivate; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -5539,7 +5528,6 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2022 Sentry. All rights reserved."; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = io.sentry.SentryPrivate; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/Sources/Configuration/SDK.xcconfig b/Sources/Configuration/SDK.xcconfig index 8450cd5d63e..acfcecedd68 100644 --- a/Sources/Configuration/SDK.xcconfig +++ b/Sources/Configuration/SDK.xcconfig @@ -40,11 +40,6 @@ ONLY_ACTIVE_ARCH[config=Debug] = YES GCC_OPTIMIZATION_LEVEL[config=Debug] = 0 COPY_PHASE_STRIP[config=Debug] = NO -LD_RUNPATH_SEARCH_PATHS[sdk=macosx*] = $(inherited) @executable_path/../Frameworks @loader_path/../Frameworks; -LD_RUNPATH_SEARCH_PATHS[sdk=iphone*] = $(inherited) @executable_path/Frameworks @loader_path/Frameworks; -LD_RUNPATH_SEARCH_PATHS[sdk=watch*] = $(inherited) @executable_path/Frameworks @loader_path/Frameworks; -LD_RUNPATH_SEARCH_PATHS[sdk=appletv*] = $(inherited) @executable_path/Frameworks @loader_path/Frameworks; - OTHER_LDFLAGS[sdk=watch*] = $(inherited) -framework WatchKit SUPPORTS_MACCATALYST = YES From 4ecd1bb3931a6759cde666c0b2b7fce0287b3fcc Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Thu, 5 Oct 2023 13:09:43 -0700 Subject: [PATCH 31/38] meta: update ruby version and gem/brew bundles (#3324) --- .ruby-version | 2 +- Brewfile.lock.json | 88 +++++++++++++++++++++++----------------------- Gemfile.lock | 18 +++++----- 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/.ruby-version b/.ruby-version index 460b6fd4048..be94e6f53db 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.5 \ No newline at end of file +3.2.2 diff --git a/Brewfile.lock.json b/Brewfile.lock.json index cf6fb43c40c..56c3d19b71d 100644 --- a/Brewfile.lock.json +++ b/Brewfile.lock.json @@ -2,55 +2,45 @@ "entries": { "brew": { "clang-format": { - "version": "17.0.1", + "version": "17.0.2", "bottle": { "rebuild": 0, "root_url": "https://ghcr.io/v2/homebrew/core", "files": { "arm64_sonoma": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/clang-format/blobs/sha256:d68f5c8fbe644e11889d82ad010475ed66dd2e13a29ac7b1b46399bd68b1a56d", - "sha256": "d68f5c8fbe644e11889d82ad010475ed66dd2e13a29ac7b1b46399bd68b1a56d" + "url": "https://ghcr.io/v2/homebrew/core/clang-format/blobs/sha256:1efd2fee1635d34114bd9d6daa1390b66a8df8621feec3c6650d6ef9ba4ade8d", + "sha256": "1efd2fee1635d34114bd9d6daa1390b66a8df8621feec3c6650d6ef9ba4ade8d" }, "arm64_ventura": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/clang-format/blobs/sha256:9a89fc6033b331f04046258e64004c0bac2ead4f383348b97e5e87deecec5c29", - "sha256": "9a89fc6033b331f04046258e64004c0bac2ead4f383348b97e5e87deecec5c29" + "url": "https://ghcr.io/v2/homebrew/core/clang-format/blobs/sha256:dd037c2099365c36fe7f98b7a88fd9b38e4e98f176c272ddf647999b52961e68", + "sha256": "dd037c2099365c36fe7f98b7a88fd9b38e4e98f176c272ddf647999b52961e68" }, "arm64_monterey": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/clang-format/blobs/sha256:8d453796bb77e3cd31f8836d499289ab1cef6ed07bef193eaf3ca924c42bdf18", - "sha256": "8d453796bb77e3cd31f8836d499289ab1cef6ed07bef193eaf3ca924c42bdf18" - }, - "arm64_big_sur": { - "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/clang-format/blobs/sha256:86671d1a34300a72be994889e2ee44fe6850f2b802e253ee0b8712b5ec7f368b", - "sha256": "86671d1a34300a72be994889e2ee44fe6850f2b802e253ee0b8712b5ec7f368b" + "url": "https://ghcr.io/v2/homebrew/core/clang-format/blobs/sha256:2d6db6df5d9dc8dfe2261d92e24979a7ab95c03ab630696ce000a343f375e262", + "sha256": "2d6db6df5d9dc8dfe2261d92e24979a7ab95c03ab630696ce000a343f375e262" }, "sonoma": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/clang-format/blobs/sha256:48aab6b1a3267b7f8315b30cfcaf489d63affeabf8fd6b643d85964ac55e032c", - "sha256": "48aab6b1a3267b7f8315b30cfcaf489d63affeabf8fd6b643d85964ac55e032c" + "url": "https://ghcr.io/v2/homebrew/core/clang-format/blobs/sha256:fe42f4d3a1ae819f7da81d811b06cd3aca135d4169f5f7f0e6643e1ba82ad760", + "sha256": "fe42f4d3a1ae819f7da81d811b06cd3aca135d4169f5f7f0e6643e1ba82ad760" }, "ventura": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/clang-format/blobs/sha256:788c2638a518ee5c3c017c3360d732dc222955e6aaa7cf31ee162c8e9610d8a1", - "sha256": "788c2638a518ee5c3c017c3360d732dc222955e6aaa7cf31ee162c8e9610d8a1" + "url": "https://ghcr.io/v2/homebrew/core/clang-format/blobs/sha256:dbca4323c6321af28c7c0e15ffc1c9d8d62fb0b8e74709c500d1724d23a292ba", + "sha256": "dbca4323c6321af28c7c0e15ffc1c9d8d62fb0b8e74709c500d1724d23a292ba" }, "monterey": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/clang-format/blobs/sha256:fa6015cf39648535b2c33f486b25e144bf6ff3ff689c2d99b9e32b24e8cc04c6", - "sha256": "fa6015cf39648535b2c33f486b25e144bf6ff3ff689c2d99b9e32b24e8cc04c6" - }, - "big_sur": { - "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/clang-format/blobs/sha256:4bb72238533d316c3dc4963848ebfcfad07f201cd682425ee24d4d2cf712bd46", - "sha256": "4bb72238533d316c3dc4963848ebfcfad07f201cd682425ee24d4d2cf712bd46" + "url": "https://ghcr.io/v2/homebrew/core/clang-format/blobs/sha256:e00953e72bf88cd9ec6067d0d6939ec01fe92b555ea00561681ea71ff4556d03", + "sha256": "e00953e72bf88cd9ec6067d0d6939ec01fe92b555ea00561681ea71ff4556d03" }, "x86_64_linux": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/clang-format/blobs/sha256:6d17800e3c917c4596051d34745880c45c0dfcf81a6e2fc7440f8b95fb1967ef", - "sha256": "6d17800e3c917c4596051d34745880c45c0dfcf81a6e2fc7440f8b95fb1967ef" + "url": "https://ghcr.io/v2/homebrew/core/clang-format/blobs/sha256:64a41e19b976c1725c0f47d7933c5ff34c153c60b68354a503410e41efbfc5e8", + "sha256": "64a41e19b976c1725c0f47d7933c5ff34c153c60b68354a503410e41efbfc5e8" } } } @@ -70,45 +60,45 @@ } }, "swiftlint": { - "version": "0.52.4", + "version": "0.53.0", "bottle": { - "rebuild": 1, + "rebuild": 0, "root_url": "https://ghcr.io/v2/homebrew/core", "files": { "arm64_sonoma": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:5e5803cfd7481bf6b5c0de58364add25be04b1f723936e72aa87e195f6469b6e", - "sha256": "5e5803cfd7481bf6b5c0de58364add25be04b1f723936e72aa87e195f6469b6e" + "url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:240ccda9de55d948d0c635798079074099bfcb73ffda41428900fdc748aeea7b", + "sha256": "240ccda9de55d948d0c635798079074099bfcb73ffda41428900fdc748aeea7b" }, "arm64_ventura": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:718f5989e0909ea736848e0d6f32d07cfa20bb23cab5fb9989803872e88d1a29", - "sha256": "718f5989e0909ea736848e0d6f32d07cfa20bb23cab5fb9989803872e88d1a29" + "url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:7b7ceb7896c6833965cc4eac9001255d8adde6c5432045d5a8ab6aea8a9e81d9", + "sha256": "7b7ceb7896c6833965cc4eac9001255d8adde6c5432045d5a8ab6aea8a9e81d9" }, "arm64_monterey": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:bcc2c13aa6c01634b382991df048bb331caa5eec230fff33ddbab19258a30c22", - "sha256": "bcc2c13aa6c01634b382991df048bb331caa5eec230fff33ddbab19258a30c22" + "url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:78c2a4c3f4a2f6847b484527b0f0f916da71e3ee29e49890fd44b63fe7b38e26", + "sha256": "78c2a4c3f4a2f6847b484527b0f0f916da71e3ee29e49890fd44b63fe7b38e26" }, "sonoma": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:69bb850978f4b454fa1930d1cda7fb39381a08af540320ac6eec5dfc834ea04f", - "sha256": "69bb850978f4b454fa1930d1cda7fb39381a08af540320ac6eec5dfc834ea04f" + "url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:abdca78dd8a8bd268053b3be195fe891bb74aef5502ab3a6b871ae0c6bb04540", + "sha256": "abdca78dd8a8bd268053b3be195fe891bb74aef5502ab3a6b871ae0c6bb04540" }, "ventura": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:5aec3b872abfead26c702334f0cffddb8ea653481720d7c1248ad836be37a975", - "sha256": "5aec3b872abfead26c702334f0cffddb8ea653481720d7c1248ad836be37a975" + "url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:be711c707bf3b49fa0dd6e2ae576b309aad620f9b56a2c6e7b1ac5cf35cf652a", + "sha256": "be711c707bf3b49fa0dd6e2ae576b309aad620f9b56a2c6e7b1ac5cf35cf652a" }, "monterey": { "cellar": ":any_skip_relocation", - "url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:e3171413a8649150601f777176af1dae458cb4be35aa1185e31636db1bb7124a", - "sha256": "e3171413a8649150601f777176af1dae458cb4be35aa1185e31636db1bb7124a" + "url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:13487d68a971dbe035019364e19d70641af2a18c06e52925d238685b384a7979", + "sha256": "13487d68a971dbe035019364e19d70641af2a18c06e52925d238685b384a7979" }, "x86_64_linux": { "cellar": "/home/linuxbrew/.linuxbrew/Cellar", - "url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:e8ec45e149d2e33295ddcd87a142389492176b51d0c2216127ae00d3ade33a6b", - "sha256": "e8ec45e149d2e33295ddcd87a142389492176b51d0c2216127ae00d3ade33a6b" + "url": "https://ghcr.io/v2/homebrew/core/swiftlint/blobs/sha256:fbbc56fccfcfcd34564feb7325567e2ff3638d3c609396a5c4aa13311c7b26e0", + "sha256": "fbbc56fccfcfcd34564feb7325567e2ff3638d3c609396a5c4aa13311c7b26e0" } } } @@ -119,6 +109,11 @@ "rebuild": 0, "root_url": "https://ghcr.io/v2/homebrew/core", "files": { + "arm64_sonoma": { + "cellar": ":any_skip_relocation", + "url": "https://ghcr.io/v2/homebrew/core/carthage/blobs/sha256:ba4ee0fbdfad0f3759def555de4c32802bc56993c97a82d0b515247de138f773", + "sha256": "ba4ee0fbdfad0f3759def555de4c32802bc56993c97a82d0b515247de138f773" + }, "arm64_ventura": { "cellar": ":any_skip_relocation", "url": "https://ghcr.io/v2/homebrew/core/carthage/blobs/sha256:9adaaa9609a4a96f6cf41ac3f135eeb988ff8e61f13e541f9ab2455a4686ca2d", @@ -134,6 +129,11 @@ "url": "https://ghcr.io/v2/homebrew/core/carthage/blobs/sha256:76c60dc59aa5a569816d55e3db88bda26339f481e74f84b3ce562b326264ae73", "sha256": "76c60dc59aa5a569816d55e3db88bda26339f481e74f84b3ce562b326264ae73" }, + "sonoma": { + "cellar": ":any_skip_relocation", + "url": "https://ghcr.io/v2/homebrew/core/carthage/blobs/sha256:d05d4f1206685386ecc73d690bcfd968ee868ba0537522a7f3bc2d942b02985d", + "sha256": "d05d4f1206685386ecc73d690bcfd968ee868ba0537522a7f3bc2d942b02985d" + }, "ventura": { "cellar": ":any_skip_relocation", "url": "https://ghcr.io/v2/homebrew/core/carthage/blobs/sha256:8d3c23086c08866b1431ac914090cee8e8ee610c6f3d3323e2f9d9a5bc31cd01", @@ -381,12 +381,12 @@ "macOS": "12.6" }, "ventura": { - "HOMEBREW_VERSION": "4.1.13", + "HOMEBREW_VERSION": "4.1.14", "HOMEBREW_PREFIX": "/opt/homebrew", "Homebrew/homebrew-core": "api", - "CLT": "", + "CLT": "15.0.0.0.1.1694021235", "Xcode": "15.0", - "macOS": "13.5.2" + "macOS": "13.6" } } } diff --git a/Gemfile.lock b/Gemfile.lock index 27cdf330324..585db8cc051 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,16 +16,16 @@ GEM artifactory (3.0.15) atomos (0.1.3) aws-eventstream (1.2.0) - aws-partitions (1.828.0) - aws-sdk-core (3.183.1) + aws-partitions (1.832.0) + aws-sdk-core (3.185.0) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.5) jmespath (~> 1, >= 1.6.1) - aws-sdk-kms (1.71.0) - aws-sdk-core (~> 3, >= 3.177.0) + aws-sdk-kms (1.72.0) + aws-sdk-core (~> 3, >= 3.184.0) aws-sigv4 (~> 1.1) - aws-sdk-s3 (1.135.0) + aws-sdk-s3 (1.136.0) aws-sdk-core (~> 3, >= 3.181.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.6) @@ -86,7 +86,7 @@ GEM escape (0.0.4) ethon (0.16.0) ffi (>= 1.15.0) - excon (0.103.0) + excon (0.104.0) faraday (1.10.3) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) @@ -211,7 +211,7 @@ GEM jwt (2.7.1) mime-types (3.5.1) mime-types-data (~> 3.2015) - mime-types-data (3.2023.0808) + mime-types-data (3.2023.1003) mini_magick (4.12.0) mini_mime (1.1.5) mini_portile2 (2.8.4) @@ -278,7 +278,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.8.2) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) webrick (1.8.1) word_wrap (1.0.0) xcodeproj (1.23.0) @@ -306,4 +306,4 @@ DEPENDENCIES xcpretty BUNDLED WITH - 2.4.17 + 2.4.20 From 86d42470d0a6f67d057b46504b48f248efb62ed5 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Fri, 6 Oct 2023 11:02:29 -0700 Subject: [PATCH 32/38] fix: remove relative component of import (#3332) Co-authored-by: Jim Boulter --- Sources/Sentry/include/SentryProfiledTracerConcurrency.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Sentry/include/SentryProfiledTracerConcurrency.h b/Sources/Sentry/include/SentryProfiledTracerConcurrency.h index 9156dbdf50c..7d5fdff2827 100644 --- a/Sources/Sentry/include/SentryProfiledTracerConcurrency.h +++ b/Sources/Sentry/include/SentryProfiledTracerConcurrency.h @@ -1,5 +1,5 @@ -#import "../Public/SentryId.h" #import "SentryCompiler.h" +#import "SentryId.h" #import "SentryProfilingConditionals.h" #import From ff64ac76ca60abeef4f309d10f4c4ac5fff9f0ff Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Wed, 11 Oct 2023 09:04:14 +0200 Subject: [PATCH 33/38] rename replaceOptionIntegrations --- SentryTestUtils/MainThreadTestIntegration.swift | 2 +- Tests/SentryTests/SentrySDKTests.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SentryTestUtils/MainThreadTestIntegration.swift b/SentryTestUtils/MainThreadTestIntegration.swift index cdf5c572577..2acad6b21ff 100644 --- a/SentryTestUtils/MainThreadTestIntegration.swift +++ b/SentryTestUtils/MainThreadTestIntegration.swift @@ -10,7 +10,7 @@ public class MainThreadTestIntegration: NSObject, SentryIntegrationProtocol { return true } - public static func replaceOptionIntegrations(_ options: Options) { + public static func replaceIntegrationsOn(_ options: Options) { options.integrations = [ NSStringFromClass(MainThreadTestIntegration.self) ] } } diff --git a/Tests/SentryTests/SentrySDKTests.swift b/Tests/SentryTests/SentrySDKTests.swift index 080dc1afd4c..4b52c14f045 100644 --- a/Tests/SentryTests/SentrySDKTests.swift +++ b/Tests/SentryTests/SentrySDKTests.swift @@ -658,7 +658,7 @@ class SentrySDKTests: XCTestCase { let expect = expectation(description: "SDK Initialization") DispatchQueue.global(qos: .background).async { SentrySDK.start { options in - MainThreadTestIntegration.replaceOptionIntegrations(options) + MainThreadTestIntegration.replaceIntegrationsOn(options) } expect.fulfill() } From d174abf94589513986f8217c6d7f6f206e74e191 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Wed, 11 Oct 2023 09:05:30 +0200 Subject: [PATCH 34/38] fix changelog --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f269fcb8b19..6fbc913ee67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,6 @@ - Start SDK on the main thread (#3291) - App hang with race condition for tick counter (#3290) - Remove "duplicate library" warning (#3312) -- Remove unnecessaries build settings (#3325) - Remove unnecessary build settings (#3325) ## 8.13.0 From 0c88c2351b1526708352ceed9fdd33b2afa20621 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Wed, 11 Oct 2023 09:49:48 +0200 Subject: [PATCH 35/38] Make SDK init synchronous --- CHANGELOG.md | 2 +- SentryTestUtils/MainThreadTestIntegration.swift | 4 ---- Sources/Sentry/SentrySDK.m | 5 ++++- Sources/Sentry/SentryThreadWrapper.m | 9 +++++++++ Sources/Sentry/include/SentryThreadWrapper.h | 10 ++++++++++ Tests/SentryTests/SentrySDKTests.swift | 13 +++++++------ 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fbc913ee67..21c41a74370 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Fixes -- Start SDK on the main thread (#3291) +- Always start SDK on the main thread (#3291) - App hang with race condition for tick counter (#3290) - Remove "duplicate library" warning (#3312) - Remove unnecessary build settings (#3325) diff --git a/SentryTestUtils/MainThreadTestIntegration.swift b/SentryTestUtils/MainThreadTestIntegration.swift index 2acad6b21ff..aace23ff37f 100644 --- a/SentryTestUtils/MainThreadTestIntegration.swift +++ b/SentryTestUtils/MainThreadTestIntegration.swift @@ -9,8 +9,4 @@ public class MainThreadTestIntegration: NSObject, SentryIntegrationProtocol { installedInTheMainThread = Thread.isMainThread return true } - - public static func replaceIntegrationsOn(_ options: Options) { - options.integrations = [ NSStringFromClass(MainThreadTestIntegration.self) ] - } } diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index cf56d4fd2bc..e8f95fad84a 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -137,7 +137,10 @@ + (void)setStartInvocations:(NSUInteger)value + (void)startWithOptions:(SentryOptions *)options { - [SentryThreadWrapper onMainThread:^{ + // We have to call the init on the main thread synchronously to guarantee the SDK gets + // initialized. Otherwise, users would init the SDK, and calls directly after would have + // undefined behavior as the SDK might not be initialized yet. + [SentryThreadWrapper onMainThreadSync:^{ startInvocations++; [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; diff --git a/Sources/Sentry/SentryThreadWrapper.m b/Sources/Sentry/SentryThreadWrapper.m index c11e6478dbd..9458c517391 100644 --- a/Sources/Sentry/SentryThreadWrapper.m +++ b/Sources/Sentry/SentryThreadWrapper.m @@ -28,6 +28,15 @@ + (void)onMainThread:(void (^)(void))block } } ++ (void)onMainThreadSync:(void (^)(void))block +{ + if ([NSThread isMainThread]) { + block(); + } else { + dispatch_sync(dispatch_get_main_queue(), block); + } +} + @end NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/include/SentryThreadWrapper.h b/Sources/Sentry/include/SentryThreadWrapper.h index 9ed3d20d2a5..a75b1a948df 100644 --- a/Sources/Sentry/include/SentryThreadWrapper.h +++ b/Sources/Sentry/include/SentryThreadWrapper.h @@ -23,6 +23,16 @@ NS_ASSUME_NONNULL_BEGIN */ + (void)onMainThread:(void (^)(void))block; +/** + * Ensure a block runs on the main thread. If called from the main thread, execute the block + * synchronously. If called from a non-main thread, then dispatch the block to the main queue + * synchronously. + * + * @warning If the main thread is blocked by anything, this will also block the call to this + * function. + */ ++ (void)onMainThreadSync:(void (^)(void))block; + @end NS_ASSUME_NONNULL_END diff --git a/Tests/SentryTests/SentrySDKTests.swift b/Tests/SentryTests/SentrySDKTests.swift index 4b52c14f045..c763e447361 100644 --- a/Tests/SentryTests/SentrySDKTests.swift +++ b/Tests/SentryTests/SentrySDKTests.swift @@ -654,18 +654,19 @@ class SentrySDKTests: XCTestCase { XCTAssertEqual(flushTimeout, transport.flushInvocations.first) } - func testStartInTheMainThread() { + func testStartOnTheMainThread() { let expect = expectation(description: "SDK Initialization") DispatchQueue.global(qos: .background).async { SentrySDK.start { options in - MainThreadTestIntegration.replaceIntegrationsOn(options) + options.integrations = [ NSStringFromClass(MainThreadTestIntegration.self) ] } + + let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first { integration in integration is MainThreadTestIntegration } as? MainThreadTestIntegration + XCTAssertEqual(mainThreadIntegration?.installedInTheMainThread, true, "SDK is not being initialized in the main thread") + expect.fulfill() } - wait(for: [expect], timeout: 0.5) - - let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first { integration in integration is MainThreadTestIntegration } as? MainThreadTestIntegration - XCTAssertEqual(mainThreadIntegration?.installedInTheMainThread, true, "SDK is not being initialized in the main thread") + wait(for: [expect], timeout: 1.0) } #if SENTRY_HAS_UIKIT From e8759175b135d48a8500260f714d40be82f1ff55 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Wed, 11 Oct 2023 10:57:29 +0200 Subject: [PATCH 36/38] change back to init async --- Sentry.xcodeproj/project.pbxproj | 2 +- .../MainThreadTestIntegration.swift | 12 ------- Sources/Sentry/Public/SentrySDK.h | 6 ++++ Sources/Sentry/SentrySDK.m | 8 ++--- Sources/Sentry/SentryThreadWrapper.m | 9 ------ Sources/Sentry/include/SentryThreadWrapper.h | 10 ------ Tests/SentryTests/SentrySDKTests.swift | 31 ++++++++++++++----- .../TestUtils/MainThreadTestIntegration.swift | 26 ++++++++++++++++ develop-docs/DECISIONS.md | 13 ++++++++ 9 files changed, 74 insertions(+), 43 deletions(-) delete mode 100644 SentryTestUtils/MainThreadTestIntegration.swift create mode 100644 Tests/SentryTests/TestUtils/MainThreadTestIntegration.swift diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index 28225f7a109..d8bcfc05c89 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -3054,6 +3054,7 @@ 62F226B829A37C270038080D /* SentryBooleanSerialization.h */, 62F226B629A37C120038080D /* SentryBooleanSerialization.m */, 62B86CFB29F052BB008F3947 /* SentryTestLogConfig.m */, + D87FA2882AB9EB06007DE933 /* MainThreadTestIntegration.swift */, ); path = TestUtils; sourceTree = ""; @@ -3184,7 +3185,6 @@ 84281C4D2A579A0C00EE88F2 /* SentryProfilerMocksSwiftCompatible.mm */, 84AC61DA29F7654A009EEF61 /* TestDispatchSourceWrapper.swift */, 84A5D75A29D5170700388BFA /* TimeInterval+Sentry.swift */, - D87FA2882AB9EB06007DE933 /* MainThreadTestIntegration.swift */, 7B30B68126527C55006B2752 /* TestDisplayLinkWrapper.swift */, 8E25C97425F8511A00DC215B /* TestRandom.swift */, 7BE3C7762445E50A00A38442 /* TestCurrentDateProvider.swift */, diff --git a/SentryTestUtils/MainThreadTestIntegration.swift b/SentryTestUtils/MainThreadTestIntegration.swift deleted file mode 100644 index aace23ff37f..00000000000 --- a/SentryTestUtils/MainThreadTestIntegration.swift +++ /dev/null @@ -1,12 +0,0 @@ -import Foundation -import Sentry - -public class MainThreadTestIntegration: NSObject, SentryIntegrationProtocol { - - public var installedInTheMainThread = false - - public func install(with options: Options) -> Bool { - installedInTheMainThread = Thread.isMainThread - return true - } -} diff --git a/Sources/Sentry/Public/SentrySDK.h b/Sources/Sentry/Public/SentrySDK.h index 344eb1ffe0b..10777f6e3db 100644 --- a/Sources/Sentry/Public/SentrySDK.h +++ b/Sources/Sentry/Public/SentrySDK.h @@ -27,12 +27,18 @@ SENTRY_NO_INIT /** * Inits and configures Sentry (SentryHub, SentryClient) and sets up all integrations. Make sure to * set a valid DSN. + * + * @discussion Call this method on the main thread. When calling it from a background thread, the + * SDK starts on the main thread async and can take some time until the SDK is fully launched. */ + (void)startWithOptions:(SentryOptions *)options NS_SWIFT_NAME(start(options:)); /** * Inits and configures Sentry (SentryHub, SentryClient) and sets up all integrations. Make sure to * set a valid DSN. + * + * @discussion Call this method on the main thread. When calling it from a background thread, the + * SDK starts on the main thread async and can take some time until the SDK is fully launched. */ + (void)startWithConfigureOptions:(void (^)(SentryOptions *options))configureOptions NS_SWIFT_NAME(start(configureOptions:)); diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index e8f95fad84a..c81bf2ef219 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -137,10 +137,10 @@ + (void)setStartInvocations:(NSUInteger)value + (void)startWithOptions:(SentryOptions *)options { - // We have to call the init on the main thread synchronously to guarantee the SDK gets - // initialized. Otherwise, users would init the SDK, and calls directly after would have - // undefined behavior as the SDK might not be initialized yet. - [SentryThreadWrapper onMainThreadSync:^{ + // We accept the tradeoff that the SDK might not be fully initialized directly after + // initializing it on a background thread because scheduling the init synchronously on the main + // thread could lead to deadlocks. + [SentryThreadWrapper onMainThread:^{ startInvocations++; [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; diff --git a/Sources/Sentry/SentryThreadWrapper.m b/Sources/Sentry/SentryThreadWrapper.m index 9458c517391..c11e6478dbd 100644 --- a/Sources/Sentry/SentryThreadWrapper.m +++ b/Sources/Sentry/SentryThreadWrapper.m @@ -28,15 +28,6 @@ + (void)onMainThread:(void (^)(void))block } } -+ (void)onMainThreadSync:(void (^)(void))block -{ - if ([NSThread isMainThread]) { - block(); - } else { - dispatch_sync(dispatch_get_main_queue(), block); - } -} - @end NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/include/SentryThreadWrapper.h b/Sources/Sentry/include/SentryThreadWrapper.h index a75b1a948df..9ed3d20d2a5 100644 --- a/Sources/Sentry/include/SentryThreadWrapper.h +++ b/Sources/Sentry/include/SentryThreadWrapper.h @@ -23,16 +23,6 @@ NS_ASSUME_NONNULL_BEGIN */ + (void)onMainThread:(void (^)(void))block; -/** - * Ensure a block runs on the main thread. If called from the main thread, execute the block - * synchronously. If called from a non-main thread, then dispatch the block to the main queue - * synchronously. - * - * @warning If the main thread is blocked by anything, this will also block the call to this - * function. - */ -+ (void)onMainThreadSync:(void (^)(void))block; - @end NS_ASSUME_NONNULL_END diff --git a/Tests/SentryTests/SentrySDKTests.swift b/Tests/SentryTests/SentrySDKTests.swift index c763e447361..3ad7532d5cf 100644 --- a/Tests/SentryTests/SentrySDKTests.swift +++ b/Tests/SentryTests/SentrySDKTests.swift @@ -655,18 +655,21 @@ class SentrySDKTests: XCTestCase { } func testStartOnTheMainThread() { - let expect = expectation(description: "SDK Initialization") + + let expectation = expectation(description: "MainThreadTestIntegration install called") + MainThreadTestIntegration.expectation = expectation + DispatchQueue.global(qos: .background).async { SentrySDK.start { options in options.integrations = [ NSStringFromClass(MainThreadTestIntegration.self) ] } - - let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first { integration in integration is MainThreadTestIntegration } as? MainThreadTestIntegration - XCTAssertEqual(mainThreadIntegration?.installedInTheMainThread, true, "SDK is not being initialized in the main thread") - - expect.fulfill() } - wait(for: [expect], timeout: 1.0) + + wait(for: [expectation], timeout: 1.0) + + let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first { integration in integration is MainThreadTestIntegration } as? MainThreadTestIntegration + XCTAssertEqual(mainThreadIntegration?.installedInTheMainThread, true, "SDK is not being initialized in the main thread") + } #if SENTRY_HAS_UIKIT @@ -788,3 +791,17 @@ class SentrySDKTests: XCTestCase { fixture.currentDate.setDate(date: SentryDependencyContainer.sharedInstance().dateProvider.date().addingTimeInterval(bySeconds)) } } + +public class MainThreadTestIntegration: NSObject, SentryIntegrationProtocol { + + static var expectation: XCTestExpectation? + + public var installedInTheMainThread = false + + public func install(with options: Options) -> Bool { + installedInTheMainThread = Thread.isMainThread + MainThreadTestIntegration.expectation?.fulfill() + MainThreadTestIntegration.expectation = nil + return true + } +} diff --git a/Tests/SentryTests/TestUtils/MainThreadTestIntegration.swift b/Tests/SentryTests/TestUtils/MainThreadTestIntegration.swift new file mode 100644 index 00000000000..85598f9a394 --- /dev/null +++ b/Tests/SentryTests/TestUtils/MainThreadTestIntegration.swift @@ -0,0 +1,26 @@ +import Foundation +import Sentry + +public class MainThreadTestIntegration: NSObject, SentryIntegrationProtocol { + + private static var dispatchGroup: DispatchGroup? + + public var installedInTheMainThread = false + + public func install(with options: Options) -> Bool { + installedInTheMainThread = Thread.isMainThread + MainThreadTestIntegration.dispatchGroup?.leave() + return true + } + + public static func enterDispatchGroup() { + dispatchGroup = DispatchGroup() + dispatchGroup?.enter() + } + + public static func waitForInstall() -> DispatchTimeoutResult { + let result = MainThreadTestIntegration.dispatchGroup?.wait(timeout: .now() + 1.0) ?? DispatchTimeoutResult.timedOut + dispatchGroup = nil + return result + } +} diff --git a/develop-docs/DECISIONS.md b/develop-docs/DECISIONS.md index 119e2e8d87b..26b10ca758c 100644 --- a/develop-docs/DECISIONS.md +++ b/develop-docs/DECISIONS.md @@ -127,3 +127,16 @@ This way, if these files are changed, we will be reminded to test the changes wi Additionally, two new 'make' commands(test-alamofire, test-homekit) are being added to the project to assist in testing the Sentry SDK in third-party projects. Related to [GH-2916](https://github.com/getsentry/sentry-cocoa/pull/2916) + +## Async SDK init on main thread + +Date: October 11th 2023 +Contributors: @philipphofmann, @brustolin + +We decided to initialize the SDK on the main thread async when being initialized from a background thread. +We accept the tradeoff that the SDK might not be fully initialized directly after initializing it on a background +thread because scheduling the init synchronously on the main thread could lead to deadlocks, such as https://github.com/getsentry/sentry-cocoa/issues/3277. + +Related links: + +- https://github.com/getsentry/sentry-cocoa/pull/3291 From 0f5d42c00c22bb5b2504b4ca5b21f7d377928380 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Wed, 11 Oct 2023 11:03:06 +0200 Subject: [PATCH 37/38] remove not needed file --- Sentry.xcodeproj/project.pbxproj | 4 --- .../TestUtils/MainThreadTestIntegration.swift | 26 ------------------- 2 files changed, 30 deletions(-) delete mode 100644 Tests/SentryTests/TestUtils/MainThreadTestIntegration.swift diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index d8bcfc05c89..72f202e9721 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -776,7 +776,6 @@ D86F419827C8FEFA00490520 /* SentryCoreDataTrackerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D86F419727C8FEFA00490520 /* SentryCoreDataTrackerExtension.swift */; }; D8751FA5274743710032F4DE /* SentryNSURLSessionTaskSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8751FA4274743710032F4DE /* SentryNSURLSessionTaskSearchTests.swift */; }; D875ED0B276CC84700422FAC /* SentryNSDataTrackerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D875ED0A276CC84700422FAC /* SentryNSDataTrackerTests.swift */; }; - D87FA2892AB9EB06007DE933 /* MainThreadTestIntegration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D87FA2882AB9EB06007DE933 /* MainThreadTestIntegration.swift */; }; D880E3A728573E87008A90DB /* SentryBaggageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D880E3A628573E87008A90DB /* SentryBaggageTests.swift */; }; D884A20527C80F6300074664 /* SentryCoreDataTrackerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = D884A20327C80F2700074664 /* SentryCoreDataTrackerTest.swift */; }; D885266427739D01001269FC /* SentryFileIOTrackingIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D885266327739D01001269FC /* SentryFileIOTrackingIntegrationTests.swift */; }; @@ -1729,7 +1728,6 @@ D8751FA4274743710032F4DE /* SentryNSURLSessionTaskSearchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSURLSessionTaskSearchTests.swift; sourceTree = ""; }; D8757D142A209F7300BFEFCC /* SentrySampleDecision+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentrySampleDecision+Private.h"; path = "include/SentrySampleDecision+Private.h"; sourceTree = ""; }; D875ED0A276CC84700422FAC /* SentryNSDataTrackerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SentryNSDataTrackerTests.swift; sourceTree = ""; }; - D87FA2882AB9EB06007DE933 /* MainThreadTestIntegration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainThreadTestIntegration.swift; sourceTree = ""; }; D880E3A628573E87008A90DB /* SentryBaggageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryBaggageTests.swift; sourceTree = ""; }; D880E3B02860A5A0008A90DB /* SentryEvent+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryEvent+Private.h"; path = "include/SentryEvent+Private.h"; sourceTree = ""; }; D884A20327C80F2700074664 /* SentryCoreDataTrackerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCoreDataTrackerTest.swift; sourceTree = ""; }; @@ -3054,7 +3052,6 @@ 62F226B829A37C270038080D /* SentryBooleanSerialization.h */, 62F226B629A37C120038080D /* SentryBooleanSerialization.m */, 62B86CFB29F052BB008F3947 /* SentryTestLogConfig.m */, - D87FA2882AB9EB06007DE933 /* MainThreadTestIntegration.swift */, ); path = TestUtils; sourceTree = ""; @@ -4487,7 +4484,6 @@ 84B7FA4529B2926900AD93B1 /* TestDisplayLinkWrapper.swift in Sources */, 84AC61DB29F7654A009EEF61 /* TestDispatchSourceWrapper.swift in Sources */, 8431F01729B2851500D8DC56 /* TestSentrySystemWrapper.swift in Sources */, - D87FA2892AB9EB06007DE933 /* MainThreadTestIntegration.swift in Sources */, 84281C632A579D0700EE88F2 /* SentryProfilerMocks.mm in Sources */, 84B7FA4129B28CD200AD93B1 /* TestSentryDispatchQueueWrapper.swift in Sources */, 84B7FA3E29B28ADD00AD93B1 /* TestClient.swift in Sources */, diff --git a/Tests/SentryTests/TestUtils/MainThreadTestIntegration.swift b/Tests/SentryTests/TestUtils/MainThreadTestIntegration.swift deleted file mode 100644 index 85598f9a394..00000000000 --- a/Tests/SentryTests/TestUtils/MainThreadTestIntegration.swift +++ /dev/null @@ -1,26 +0,0 @@ -import Foundation -import Sentry - -public class MainThreadTestIntegration: NSObject, SentryIntegrationProtocol { - - private static var dispatchGroup: DispatchGroup? - - public var installedInTheMainThread = false - - public func install(with options: Options) -> Bool { - installedInTheMainThread = Thread.isMainThread - MainThreadTestIntegration.dispatchGroup?.leave() - return true - } - - public static func enterDispatchGroup() { - dispatchGroup = DispatchGroup() - dispatchGroup?.enter() - } - - public static func waitForInstall() -> DispatchTimeoutResult { - let result = MainThreadTestIntegration.dispatchGroup?.wait(timeout: .now() + 1.0) ?? DispatchTimeoutResult.timedOut - dispatchGroup = nil - return result - } -} From d2a9730a92e27a7b96593acb00f2eb915413d0f9 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Wed, 11 Oct 2023 11:05:57 +0200 Subject: [PATCH 38/38] simplify comment --- Sources/Sentry/Public/SentrySDK.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Sentry/Public/SentrySDK.h b/Sources/Sentry/Public/SentrySDK.h index 10777f6e3db..94aee0e776e 100644 --- a/Sources/Sentry/Public/SentrySDK.h +++ b/Sources/Sentry/Public/SentrySDK.h @@ -29,7 +29,7 @@ SENTRY_NO_INIT * set a valid DSN. * * @discussion Call this method on the main thread. When calling it from a background thread, the - * SDK starts on the main thread async and can take some time until the SDK is fully launched. + * SDK starts on the main thread async. */ + (void)startWithOptions:(SentryOptions *)options NS_SWIFT_NAME(start(options:)); @@ -38,7 +38,7 @@ SENTRY_NO_INIT * set a valid DSN. * * @discussion Call this method on the main thread. When calling it from a background thread, the - * SDK starts on the main thread async and can take some time until the SDK is fully launched. + * SDK starts on the main thread async. */ + (void)startWithConfigureOptions:(void (^)(SentryOptions *options))configureOptions NS_SWIFT_NAME(start(configureOptions:));