-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Synchronize useUserAccessGroup #5387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
FirebaseAuth/Sources/Auth/FIRAuth.m
Outdated
error:(NSError *_Nullable *_Nullable)outError { | ||
// self.storedUserManager is initialized asynchronously. | ||
__block FIRAuthStoredUserManager *storedUserManager; | ||
dispatch_sync(FIRAuthGlobalWorkQueue(), ^{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates the potential for deadlock because useUserAccessGroup:error:
is called from code already on the FIRAuthGlobalWorkQueue()
See
[strongSelf useUserAccessGroup:storedUserAccessGroup error:&error]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @wilhuff Good catch! PTAL at the update and let me know if you have a suggestion for a better way.
I'll see if I can add a unit test as well before merging. |
FirebaseAuth/Sources/Auth/FIRAuth.m
Outdated
- (BOOL)useUserAccessGroup:(NSString *_Nullable)accessGroup | ||
error:(NSError *_Nullable *_Nullable)outError { | ||
// Make sure that the keychain has been initialized. | ||
dispatch_semaphore_wait(_initializingKeychain, DISPATCH_TIME_FOREVER); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach of splitting internal and external usage would work just as well with your dispatch_sync
approach and would avoid needing to keep an extra semaphore (or keep waiting/re-signaling it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty much LGTM, though see comments: I don't think your test would actually trip up over the deadlock.
|
||
- (BOOL)useUserAccessGroup:(NSString *_Nullable)accessGroup | ||
error:(NSError *_Nullable *_Nullable)outError { | ||
- (BOOL)internalUseUserAccessGroup:(NSString *_Nullable)accessGroup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 532 needs to change to use the internal version and you're done.
[strongSelf useUserAccessGroup:storedUserAccessGroup error:&error]; |
The test needs to set up a stored user access group to effectively verify that the deadlock during initialization isn't happening.
- (BOOL)useUserAccessGroup:(NSString *_Nullable)accessGroup | ||
error:(NSError *_Nullable *_Nullable)outError { | ||
// self.storedUserManager is initialized asynchronously. Make sure it is done. | ||
dispatch_sync(FIRAuthGlobalWorkQueue(), ^{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking maybe it makes sense to load storedUserManager synchronously, but it requires more investigation on the impact. This should be good for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM from my side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good to me. Please improve the unit test as @wilhuff suggests.
Fix #4175