10000 Synchronize useUserAccessGroup by paulb777 · Pull Request #5387 · firebase/firebase-ios-sdk · GitHub
[go: up one dir, main page]

Skip to content

Conversation

paulb777
Copy link
Member

Fix #4175

error:(NSError *_Nullable *_Nullable)outError {
// self.storedUserManager is initialized asynchronously.
__block FIRAuthStoredUserManager *storedUserManager;
dispatch_sync(FIRAuthGlobalWorkQueue(), ^{
Copy link
Contributor

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];

Copy link
Member Author

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.

@paulb777
Copy link
Member Author

I'll see if I can add a unit test as well before merging.

- (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);
Copy link
Contributor

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).

@paulb777 paulb777 marked this pull request as draft April 16, 2020 19:21
@paulb777 paulb777 marked this pull request as ready for review April 16, 2020 19:33
Copy link
Contributor
@wilhuff wilhuff left a 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
Copy link
Contributor

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(), ^{
Copy link
Contributor

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.

Copy link
Contributor
@wilhuff wilhuff left a 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.

Copy link
Contributor
@renkelvin renkelvin left a 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.

@paulb777 paulb777 merged commit 5f7ee56 into master Apr 17, 2020
@paulb777 paulb777 deleted the pb-sync-useraccess branch April 17, 2020 21:36
schnecle pushed a commit that referenced this pull request Apr 21, 2020
ryanwilson pushed a commit that referenced this pull request Apr 24, 2020
@firebase firebase locked and limited conversation to collaborators May 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug?] Unsafe to call useUserAccessGroup immediately after FirebaseApp.configure()
5 participants
0