From cc82333b358db48e404fa86713985464fc860c2b Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Wed, 13 Dec 2017 12:00:56 +0000 Subject: [PATCH] Fix deadlock in rest.device --- Source/ARTPushActivationStateMachine.m | 6 +++--- Source/ARTRest.h | 1 + Source/ARTRest.m | 12 +++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Source/ARTPushActivationStateMachine.m b/Source/ARTPushActivationStateMachine.m index cca151076..cf0a08190 100644 --- a/Source/ARTPushActivationStateMachine.m +++ b/Source/ARTPushActivationStateMachine.m @@ -101,7 +101,7 @@ - (void)persist { - (void)deviceRegistration:(ARTErrorInfo *)error { #ifdef TARGET_OS_IOS - ARTLocalDevice *local = _rest.device; + ARTLocalDevice *local = _rest.device_nosync; if (![[UIApplication sharedApplication].delegate conformsToProtocol:@protocol(ARTPushRegistererDelegate)]) { [NSException raise:@"ARTPushRegistererDelegate must be implemented on AppDelegate" format:@""]; @@ -156,7 +156,7 @@ - (void)deviceRegistration:(ARTErrorInfo *)error { - (void)deviceUpdateRegistration:(ARTErrorInfo *)error { #ifdef TARGET_OS_IOS - ARTLocalDevice *local = _rest.device; + ARTLocalDevice *local = _rest.device_nosync; if (![[UIApplication sharedApplication].delegate conformsToProtocol:@protocol(ARTPushRegistererDelegate)]) { [NSException raise:@"ARTPushRegistererDelegate must be implemented on AppDelegate" format:@""]; @@ -218,7 +218,7 @@ - (void)deviceUpdateRegistration:(ARTErrorInfo *)error { - (void)deviceUnregistration:(ARTErrorInfo *)error { #ifdef TARGET_OS_IOS - ARTLocalDevice *local = _rest.device; + ARTLocalDevice *local = _rest.device_nosync; id delegate = [UIApplication sharedApplication].delegate; diff --git a/Source/ARTRest.h b/Source/ARTRest.h index c1f2bad09..c81bfec3a 100644 --- a/Source/ARTRest.h +++ b/Source/ARTRest.h @@ -54,6 +54,7 @@ ART_ASSUME_NONNULL_BEGIN @property (nonatomic, strong, readonly) ARTPush *push; #ifdef TARGET_OS_IOS @property (nonnull, nonatomic, readonly, getter=device) ARTLocalDevice *device; +@property (nonnull, nonatomic, readonly, getter=device_nosync) ARTLocalDevice *device_nosync; #endif @end diff --git a/Source/ARTRest.m b/Source/ARTRest.m index 4b638dde9..aa3183807 100644 --- a/Source/ARTRest.m +++ b/Source/ARTRest.m @@ -581,12 +581,18 @@ void ARTstopHandlingUncaughtExceptions(ARTRest *self) { } - (ARTLocalDevice *)device { + __block ARTLocalDevice *ret; + dispatch_sync(_queue, ^{ + ret = [self device_nosync]; + }); + return ret; +} + +- (NSString *)device_nosync { static dispatch_once_t once; static id device; dispatch_once(&once, ^{ - dispatch_sync(_queue, ^{ - device = [ARTLocalDevice load:self]; - }); + device = [ARTLocalDevice load:self]; }); return device; }