From 27abd3fdbd7207735a285b87a31d54a36307ed15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Wed, 1 Apr 2020 11:18:15 +0200 Subject: [PATCH 1/5] [expo-permissions] Remove dispatch_once_t used as a member instance --- packages/expo-permissions/ios/EXPermissions/EXPermissions.m | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/expo-permissions/ios/EXPermissions/EXPermissions.m b/packages/expo-permissions/ios/EXPermissions/EXPermissions.m index e7ec21e0d160c..ea67c695485a7 100644 --- a/packages/expo-permissions/ios/EXPermissions/EXPermissions.m +++ b/packages/expo-permissions/ios/EXPermissions/EXPermissions.m @@ -20,7 +20,6 @@ @interface EXPermissions () @property (nonatomic, strong) NSMutableDictionary> *requesters; @property (nonatomic, strong) NSMapTable> *requestersByClass; @property (nonatomic, weak) UMModuleRegistry *moduleRegistry; -@property (nonatomic) dispatch_once_t requestersFallbacksRegisteredOnce; @end @@ -209,9 +208,7 @@ + (UMPermissionStatus)statusForPermission:(NSDictionary *)permission - (id)getPermissionRequesterForType:(NSString *)type { - dispatch_once(&_requestersFallbacksRegisteredOnce, ^{ - [self ensureRequestersFallbacksAreRegistered]; - }); + [self ensureRequestersFallbacksAreRegistered]; return _requesters[type]; } From 73b5ac720a5e86a8b528bc79d4efd4bc5f41f63c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Wed, 1 Apr 2020 11:24:17 +0200 Subject: [PATCH 2/5] [ios] Backport change to SDK 37 --- .../ABI37_0_0EXPermissions/ABI37_0_0EXPermissions.m | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ios/versioned-react-native/ABI37_0_0/Expo/EXPermissions/ABI37_0_0EXPermissions/ABI37_0_0EXPermissions.m b/ios/versioned-react-native/ABI37_0_0/Expo/EXPermissions/ABI37_0_0EXPermissions/ABI37_0_0EXPermissions.m index 44d6f5bba1cb7..33c3c9e2288bd 100644 --- a/ios/versioned-react-native/ABI37_0_0/Expo/EXPermissions/ABI37_0_0EXPermissions/ABI37_0_0EXPermissions.m +++ b/ios/versioned-react-native/ABI37_0_0/Expo/EXPermissions/ABI37_0_0EXPermissions/ABI37_0_0EXPermissions.m @@ -20,7 +20,6 @@ @interface ABI37_0_0EXPermissions () @property (nonatomic, strong) NSMutableDictionary> *requesters; @property (nonatomic, strong) NSMapTable> *requestersByClass; @property (nonatomic, weak) ABI37_0_0UMModuleRegistry *moduleRegistry; -@property (nonatomic) dispatch_once_t requestersFallbacksRegisteredOnce; @end @@ -209,9 +208,7 @@ + (ABI37_0_0UMPermissionStatus)statusForPermission:(NSDictionary *)permission - (id)getPermissionRequesterForType:(NSString *)type { - dispatch_once(&_requestersFallbacksRegisteredOnce, ^{ - [self ensureRequestersFallbacksAreRegistered]; - }); + [self ensureRequestersFallbacksAreRegistered]; return _requesters[type]; } From fa73df2aa27a00b8f20f5e599170010cf248580c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Wed, 1 Apr 2020 11:24:37 +0200 Subject: [PATCH 3/5] [@unimodules/core] Do not use dispatch_once_t as an instance variable --- .../@unimodules/core/ios/UMCore/UMExportedModule.m | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/@unimodules/core/ios/UMCore/UMExportedModule.m b/packages/@unimodules/core/ios/UMCore/UMExportedModule.m index 3f99fd39a379e..f23734fc0e782 100644 --- a/packages/@unimodules/core/ios/UMCore/UMExportedModule.m +++ b/packages/@unimodules/core/ios/UMCore/UMExportedModule.m @@ -18,7 +18,6 @@ @interface UMExportedModule () @property (nonatomic, strong) dispatch_queue_t methodQueue; -@property (nonatomic, assign) dispatch_once_t methodQueueSetupOnce; @property (nonatomic, strong) NSDictionary *exportedMethods; @end @@ -55,14 +54,10 @@ - (NSDictionary *)constantsToExport - (dispatch_queue_t)methodQueue { - __weak UMExportedModule *weakSelf = self; - dispatch_once(&_methodQueueSetupOnce, ^{ - __strong UMExportedModule *strongSelf = weakSelf; - if (strongSelf) { - NSString *queueName = [NSString stringWithFormat:@"org.unimodules.%@Queue", [[strongSelf class] exportedModuleName]]; - strongSelf.methodQueue = dispatch_queue_create(queueName.UTF8String, DISPATCH_QUEUE_SERIAL); - } - }); + if (!_methodQueue) { + NSString *queueName = [NSString stringWithFormat:@"org.unimodules.%@Queue", [[self class] exportedModuleName]]; + _methodQueue = dispatch_queue_create(queueName.UTF8String, DISPATCH_QUEUE_SERIAL); + } return _methodQueue; } From 0bf9bd3c96209bc971db6b78175934f93cce5ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Wed, 1 Apr 2020 11:24:52 +0200 Subject: [PATCH 4/5] [ios] Backport removal of dispatch_once_t as an instance variable --- .../ABI34_0_0UMCore/ABI34_0_0UMExportedModule.m | 13 ++++--------- .../ABI35_0_0UMCore/ABI35_0_0UMExportedModule.m | 13 ++++--------- .../ABI36_0_0UMCore/ABI36_0_0UMExportedModule.m | 13 ++++--------- .../ABI37_0_0UMCore/ABI37_0_0UMExportedModule.m | 13 ++++--------- 4 files changed, 16 insertions(+), 36 deletions(-) diff --git a/ios/versioned-react-native/ABI34_0_0/UMCore/ABI34_0_0UMCore/ABI34_0_0UMExportedModule.m b/ios/versioned-react-native/ABI34_0_0/UMCore/ABI34_0_0UMCore/ABI34_0_0UMExportedModule.m index 619c638d4fe40..3c48d0cb58b21 100644 --- a/ios/versioned-react-native/ABI34_0_0/UMCore/ABI34_0_0UMCore/ABI34_0_0UMExportedModule.m +++ b/ios/versioned-react-native/ABI34_0_0/UMCore/ABI34_0_0UMCore/ABI34_0_0UMExportedModule.m @@ -18,7 +18,6 @@ @interface ABI34_0_0UMExportedModule () @property (nonatomic, strong) dispatch_queue_t methodQueue; -@property (nonatomic, assign) dispatch_once_t methodQueueSetupOnce; @property (nonatomic, strong) NSDictionary *exportedMethods; @end @@ -55,14 +54,10 @@ - (NSDictionary *)constantsToExport - (dispatch_queue_t)methodQueue { - __weak ABI34_0_0UMExportedModule *weakSelf = self; - dispatch_once(&_methodQueueSetupOnce, ^{ - __strong ABI34_0_0UMExportedModule *strongSelf = weakSelf; - if (strongSelf) { - NSString *queueName = [NSString stringWithFormat:@"org.unimodules.%@Queue", [[strongSelf class] exportedModuleName]]; - strongSelf.methodQueue = dispatch_queue_create(queueName.UTF8String, DISPATCH_QUEUE_SERIAL); - } - }); + if (!_methodQueue) { + NSString *queueName = [NSString stringWithFormat:@"org.unimodules.%@Queue", [[self class] exportedModuleName]]; + _methodQueue = dispatch_queue_create(queueName.UTF8String, DISPATCH_QUEUE_SERIAL); + } return _methodQueue; } diff --git a/ios/versioned-react-native/ABI35_0_0/UMCore/ABI35_0_0UMCore/ABI35_0_0UMExportedModule.m b/ios/versioned-react-native/ABI35_0_0/UMCore/ABI35_0_0UMCore/ABI35_0_0UMExportedModule.m index 095bbdeacf389..0cff30f012ab7 100644 --- a/ios/versioned-react-native/ABI35_0_0/UMCore/ABI35_0_0UMCore/ABI35_0_0UMExportedModule.m +++ b/ios/versioned-react-native/ABI35_0_0/UMCore/ABI35_0_0UMCore/ABI35_0_0UMExportedModule.m @@ -18,7 +18,6 @@ @interface ABI35_0_0UMExportedModule () @property (nonatomic, strong) dispatch_queue_t methodQueue; -@property (nonatomic, assign) dispatch_once_t methodQueueSetupOnce; @property (nonatomic, strong) NSDictionary *exportedMethods; @end @@ -55,14 +54,10 @@ - (NSDictionary *)constantsToExport - (dispatch_queue_t)methodQueue { - __weak ABI35_0_0UMExportedModule *weakSelf = self; - dispatch_once(&_methodQueueSetupOnce, ^{ - __strong ABI35_0_0UMExportedModule *strongSelf = weakSelf; - if (strongSelf) { - NSString *queueName = [NSString stringWithFormat:@"org.unimodules.%@Queue", [[strongSelf class] exportedModuleName]]; - strongSelf.methodQueue = dispatch_queue_create(queueName.UTF8String, DISPATCH_QUEUE_SERIAL); - } - }); + if (!_methodQueue) { + NSString *queueName = [NSString stringWithFormat:@"org.unimodules.%@Queue", [[self class] exportedModuleName]]; + _methodQueue = dispatch_queue_create(queueName.UTF8String, DISPATCH_QUEUE_SERIAL); + } return _methodQueue; } diff --git a/ios/versioned-react-native/ABI36_0_0/Expo/UMCore/ABI36_0_0UMCore/ABI36_0_0UMExportedModule.m b/ios/versioned-react-native/ABI36_0_0/Expo/UMCore/ABI36_0_0UMCore/ABI36_0_0UMExportedModule.m index 5011411953e68..f2a326b055574 100644 --- a/ios/versioned-react-native/ABI36_0_0/Expo/UMCore/ABI36_0_0UMCore/ABI36_0_0UMExportedModule.m +++ b/ios/versioned-react-native/ABI36_0_0/Expo/UMCore/ABI36_0_0UMCore/ABI36_0_0UMExportedModule.m @@ -18,7 +18,6 @@ @interface ABI36_0_0UMExportedModule () @property (nonatomic, strong) dispatch_queue_t methodQueue; -@property (nonatomic, assign) dispatch_once_t methodQueueSetupOnce; @property (nonatomic, strong) NSDictionary *exportedMethods; @end @@ -55,14 +54,10 @@ - (NSDictionary *)constantsToExport - (dispatch_queue_t)methodQueue { - __weak ABI36_0_0UMExportedModule *weakSelf = self; - dispatch_once(&_methodQueueSetupOnce, ^{ - __strong ABI36_0_0UMExportedModule *strongSelf = weakSelf; - if (strongSelf) { - NSString *queueName = [NSString stringWithFormat:@"org.unimodules.%@Queue", [[strongSelf class] exportedModuleName]]; - strongSelf.methodQueue = dispatch_queue_create(queueName.UTF8String, DISPATCH_QUEUE_SERIAL); - } - }); + if (!_methodQueue) { + NSString *queueName = [NSString stringWithFormat:@"org.unimodules.%@Queue", [[self class] exportedModuleName]]; + _methodQueue = dispatch_queue_create(queueName.UTF8String, DISPATCH_QUEUE_SERIAL); + } return _methodQueue; } diff --git a/ios/versioned-react-native/ABI37_0_0/Expo/UMCore/ABI37_0_0UMCore/ABI37_0_0UMExportedModule.m b/ios/versioned-react-native/ABI37_0_0/Expo/UMCore/ABI37_0_0UMCore/ABI37_0_0UMExportedModule.m index 1102647fa1c35..a9a0b43059845 100644 --- a/ios/versioned-react-native/ABI37_0_0/Expo/UMCore/ABI37_0_0UMCore/ABI37_0_0UMExportedModule.m +++ b/ios/versioned-react-native/ABI37_0_0/Expo/UMCore/ABI37_0_0UMCore/ABI37_0_0UMExportedModule.m @@ -18,7 +18,6 @@ @interface ABI37_0_0UMExportedModule () @property (nonatomic, strong) dispatch_queue_t methodQueue; -@property (nonatomic, assign) dispatch_once_t methodQueueSetupOnce; @property (nonatomic, strong) NSDictionary *exportedMethods; @end @@ -55,14 +54,10 @@ - (NSDictionary *)constantsToExport - (dispatch_queue_t)methodQueue { - __weak ABI37_0_0UMExportedModule *weakSelf = self; - dispatch_once(&_methodQueueSetupOnce, ^{ - __strong ABI37_0_0UMExportedModule *strongSelf = weakSelf; - if (strongSelf) { - NSString *queueName = [NSString stringWithFormat:@"org.unimodules.%@Queue", [[strongSelf class] exportedModuleName]]; - strongSelf.methodQueue = dispatch_queue_create(queueName.UTF8String, DISPATCH_QUEUE_SERIAL); - } - }); + if (!_methodQueue) { + NSString *queueName = [NSString stringWithFormat:@"org.unimodules.%@Queue", [[self class] exportedModuleName]]; + _methodQueue = dispatch_queue_create(queueName.UTF8String, DISPATCH_QUEUE_SERIAL); + } return _methodQueue; } From ca9a39ca8a99b3ec55c54240e8b17d022922ed61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Wed, 29 Apr 2020 13:55:59 +0200 Subject: [PATCH 5/5] [changelog] Add changelog entry --- packages/@unimodules/core/CHANGELOG.md | 2 ++ packages/expo-permissions/CHANGELOG.md | 1 + 2 files changed, 3 insertions(+) diff --git a/packages/@unimodules/core/CHANGELOG.md b/packages/@unimodules/core/CHANGELOG.md index 6a294c6841ff4..1f147070bb918 100644 --- a/packages/@unimodules/core/CHANGELOG.md +++ b/packages/@unimodules/core/CHANGELOG.md @@ -7,3 +7,5 @@ ### 🎉 New features ### 🐛 Bug fixes + +- Fixed a rare undetermined behavior that may have been a result of misuse of `dispatch_once_t` on iOS ([#7576](https://github.com/expo/expo/pull/7576) by [@sjchmiela](https://github.com/sjchmiela)) diff --git a/packages/expo-permissions/CHANGELOG.md b/packages/expo-permissions/CHANGELOG.md index f2a1ced093d91..47643e2977bb6 100644 --- a/packages/expo-permissions/CHANGELOG.md +++ b/packages/expo-permissions/CHANGELOG.md @@ -10,3 +10,4 @@ - Fix permissions in the headless mode. ([#7962](https://github.com/expo/expo/pull/7962) by [@lukmccall](https://github.com/lukmccall)) - Fixed `permission cannot be null or empty` error when asking for `WRITE_SETTINGS` permission on Android. ([#7276](https://github.com/expo/expo/pull/7276) by [@lukmccall](https://github.com/lukmccall)) +- Fixed a rare undetermined behavior that may have been a result of misuse of `dispatch_once_t` on iOS ([#7576](https://github.com/expo/expo/pull/7576) by [@sjchmiela](https://github.com/sjchmiela))