-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[Auth] Fix async/await crash from implicitly unwrapped nil error #13472
Conversation
FirebaseAuth/Sources/Swift/SystemService/AuthAPNSTokenManager.swift
Outdated
Show resolved
Hide resolved
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.
Great fix. Thanks!
@@ -68,18 +68,19 @@ | |||
kAuthGlobalWorkQueue.asyncAfter(deadline: deadline) { | |||
// Only cancel if the pending callbacks remain the same, i.e., not triggered yet. | |||
if applicableCallbacks.count == self.pendingCallbacks.count { | |||
self.callback(withToken: nil, error: nil) | |||
self.callback(.failure(AuthErrorUtils.missingAppTokenError(underlyingError: nil))) |
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.
@ncooke3
With this AuthErrorUtils.missingAppTokenError(underlyingError: nil)
, the user of the SDK has no means to know that the request timed out, apart from implementing a timeout logic on their side, right?
Would it be a solution to add an underlying timeout 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.
Hi @snapxo, that's correct that the timeout error doesn't bubble up. This getToken
API is called internally and in the case of an error (e.g. like from timeout), it actually attempts the recaptcha flow rather than bubble the error up to the user:
firebase-ios-sdk/FirebaseAuth/Sources/Swift/AuthProvider/PhoneAuthProvider.swift
Lines 321 to 326 in e76d746
do { | |
token = try await auth.tokenManager.getToken() | |
} catch { | |
return try await CodeIdentity | |
.recaptcha(reCAPTCHAFlowWithUIDelegate(withUIDelegate: uiDelegate)) | |
} |
Line 322 may throw the error you've highlighted above.
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.
Makes sense if the fallback upon every missingToken
error is the recaptcha 👌
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [firebase/firebase-ios-sdk](https://togithub.com/firebase/firebase-ios-sdk) | major | `from: "10.29.0"` -> `from: "11.1.0"` | --- ### Release Notes <details> <summary>firebase/firebase-ios-sdk (firebase/firebase-ios-sdk)</summary> ### [`v11.1.0`](https://togithub.com/firebase/firebase-ios-sdk/releases/tag/11.1.0): Firebase Apple 11.1.0 [Compare Source](https://togithub.com/firebase/firebase-ios-sdk/compare/11.0.0...11.1.0) The Firebase Apple SDK (11.1.0) is now available. For more details, see the [Firebase Apple SDK release notes.](https://firebase.google.com/support/release-notes/ios#11.1.0) To install this SDK, see [Add Firebase to your project.](https://firebase.google.com/docs/ios/setup) #### What's Changed - \[Infra] Fetch tags first when running firebase-releaser by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13411](https://togithub.com/firebase/firebase-ios-sdk/pull/13411) - Review FirebaseMessaging Tests files by [@​MojtabaHs](https://togithub.com/MojtabaHs) in [https://github.com/firebase/firebase-ios-sdk/pull/13402](https://togithub.com/firebase/firebase-ios-sdk/pull/13402) - Functions Serializer Updates by [@​yakovmanshin](https://togithub.com/yakovmanshin) in [https://github.com/firebase/firebase-ios-sdk/pull/13409](https://togithub.com/firebase/firebase-ios-sdk/pull/13409) - \[storage] Use async GTMSessionFetcher method by [@​paulb777](https://togithub.com/paulb777) in [https://github.com/firebase/firebase-ios-sdk/pull/13405](https://togithub.com/firebase/firebase-ios-sdk/pull/13405) - \[storage] Simplify callback implementation by [@​paulb777](https://togithub.com/paulb777) in [https://github.com/firebase/firebase-ios-sdk/pull/13413](https://togithub.com/firebase/firebase-ios-sdk/pull/13413) - Renamed `FUNSerializer` to `FunctionsSerializer` by [@​yakovmanshin](https://togithub.com/yakovmanshin) in [https://github.com/firebase/firebase-ios-sdk/pull/13410](https://togithub.com/firebase/firebase-ios-sdk/pull/13410) - \[Infra] Upload build-from-HEAD zips on failures by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13414](https://togithub.com/firebase/firebase-ios-sdk/pull/13414) - Move swiftformat options to a config file by [@​andrewheard](https://togithub.com/andrewheard) in [https://github.com/firebase/firebase-ios-sdk/pull/13423](https://togithub.com/firebase/firebase-ios-sdk/pull/13423) - \[v11] Upload Carthage artifacts by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13425](https://togithub.com/firebase/firebase-ios-sdk/pull/13425) - Update versions for Release 11.1.0 by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13426](https://togithub.com/firebase/firebase-ios-sdk/pull/13426) - Consistent Collections Coding in `FunctionsSerializer` by [@​yakovmanshin](https://togithub.com/yakovmanshin) in [https://github.com/firebase/firebase-ios-sdk/pull/13419](https://togithub.com/firebase/firebase-ios-sdk/pull/13419) - \[Auth] Add custom provider support for AuthProviderID by [@​paulb777](https://togithub.com/paulb777) in [https://github.com/firebase/firebase-ios-sdk/pull/13433](https://togithub.com/firebase/firebase-ios-sdk/pull/13433) - \[Infra] Attempt to fix some Crashlytics flakes by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13432](https://togithub.com/firebase/firebase-ios-sdk/pull/13432) - \[AuthErrorCode] should conform to Swift.Error by [@​paulb777](https://togithub.com/paulb777) in [https://github.com/firebase/firebase-ios-sdk/pull/13434](https://togithub.com/firebase/firebase-ios-sdk/pull/13434) - \[Infra] Fix auto-tagging in `release_testing_setup.sh` for prerelease.yml by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13427](https://togithub.com/firebase/firebase-ios-sdk/pull/13427) - \[AppCheck] Force link categories by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13435](https://togithub.com/firebase/firebase-ios-sdk/pull/13435) - \[Infra] Quiet the git fetch ([#​13436](https://togithub.com/firebase/firebase-ios-sdk/issues/13436)) by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13437](https://togithub.com/firebase/firebase-ios-sdk/pull/13437) - \[Infra] Attempt to fix post-merge tagging in prerelease.yml by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13438](https://togithub.com/firebase/firebase-ios-sdk/pull/13438) - \[Infra] Cleanup and small fixes for prerelease.yml by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13439](https://togithub.com/firebase/firebase-ios-sdk/pull/13439) - \[Infra] Remove unneeded debug code by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13441](https://togithub.com/firebase/firebase-ios-sdk/pull/13441) - \[Infra] Extend expectation wait time in FIRCLSSettingsTests.m by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13442](https://togithub.com/firebase/firebase-ios-sdk/pull/13442) - \[Infra] Apply [#​13438](https://togithub.com/firebase/firebase-ios-sdk/issues/13438) fix to other job in 'prerelease.yml' by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13443](https://togithub.com/firebase/firebase-ios-sdk/pull/13443) - Add basic EditorConfig file for repo by [@​andrewheard](https://togithub.com/andrewheard) in [https://github.com/firebase/firebase-ios-sdk/pull/13444](https://togithub.com/firebase/firebase-ios-sdk/pull/13444) - \[storage] Migrate to actor to fix a potential data race in initialization by [@​paulb777](https://togithub.com/paulb777) in [https://github.com/firebase/firebase-ios-sdk/pull/13428](https://togithub.com/firebase/firebase-ios-sdk/pull/13428) - \[Storage] Addressing Swift 6 issues with `Storage`'s instance management by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13445](https://togithub.com/firebase/firebase-ios-sdk/pull/13445) - Functions Cleanup by [@​yakovmanshin](https://togithub.com/yakovmanshin) in [https://github.com/firebase/firebase-ios-sdk/pull/13449](https://togithub.com/firebase/firebase-ios-sdk/pull/13449) - \[Infra] Removing 'release.yml' special casing in 'scripts/release_testing_setup.sh' by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13447](https://togithub.com/firebase/firebase-ios-sdk/pull/13447) - \[Storage] Manage fetcherService from a data race safe singleton by [@​paulb777](https://togithub.com/paulb777) in [https://github.com/firebase/firebase-ios-sdk/pull/13446](https://togithub.com/firebase/firebase-ios-sdk/pull/13446) - Update to xcodeproj 1.25.0 by [@​paulb777](https://togithub.com/paulb777) in [https://github.com/firebase/firebase-ios-sdk/pull/13462](https://togithub.com/firebase/firebase-ios-sdk/pull/13462) - Bump rexml from 3.2.8 to 3.3.3 in /.github/actions/notices_generation by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/firebase/firebase-ios-sdk/pull/13463](https://togithub.com/firebase/firebase-ios-sdk/pull/13463) - \[Auth] Fix async/await crash from implicitly unwrapped nil error by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13472](https://togithub.com/firebase/firebase-ios-sdk/pull/13472) - Refactored Function Calling by [@​yakovmanshin](https://togithub.com/yakovmanshin) in [https://github.com/firebase/firebase-ios-sdk/pull/13476](https://togithub.com/firebase/firebase-ios-sdk/pull/13476) - Firestore VectorValue type by [@​MarkDuckworth](https://togithub.com/MarkDuckworth) in [https://github.com/firebase/firebase-ios-sdk/pull/13404](https://togithub.com/firebase/firebase-ios-sdk/pull/13404) - \[CoreInternal] Address Swift 6 warnings (1) by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13454](https://togithub.com/firebase/firebase-ios-sdk/pull/13454) - \[Firestore] Update Firestore SPM binary to fix spm-binary workflow by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13485](https://togithub.com/firebase/firebase-ios-sdk/pull/13485) - \[Firestore] Resolve protocol conformance warnings by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13484](https://togithub.com/firebase/firebase-ios-sdk/pull/13484) - \[Auth] Update sample plist to have URL scheme for phone auth by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13487](https://togithub.com/firebase/firebase-ios-sdk/pull/13487) - \[Infra] Force link remaining categories after [#​13435](https://togithub.com/firebase/firebase-ios-sdk/issues/13435) by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13491](https://togithub.com/firebase/firebase-ios-sdk/pull/13491) - \[Firestore] Add Sendable annotation to VectorValue by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13483](https://togithub.com/firebase/firebase-ios-sdk/pull/13483) - Analytics 11.1.0 by [@​htcgh](https://togithub.com/htcgh) in [https://github.com/firebase/firebase-ios-sdk/pull/13492](https://togithub.com/firebase/firebase-ios-sdk/pull/13492) - Revert "\[Auth] Update sample plist to have URL scheme for phone auth" by [@​ncooke3](https://togithub.com/ncooke3) in [https://github.com/firebase/firebase-ios-sdk/pull/13493](https://togithub.com/firebase/firebase-ios-sdk/pull/13493) - Update Firestore SPM for 11.1.0 by [@​paulb777](https://togithub.com/paulb777) in [https://github.com/firebase/firebase-ios-sdk/pull/13497](https://togithub.com/firebase/firebase-ios-sdk/pull/13497) - 11.1.0 Changelog update by [@​paulb777](https://togithub.com/paulb777) in [https://github.com/firebase/firebase-ios-sdk/pull/13500](https://togithub.com/firebase/firebase-ios-sdk/pull/13500) - Fix and Regression Test for FirebaseUI 1199 by [@​paulb777](https://togithub.com/paulb777) in [https://github.com/firebase/firebase-ios-sdk/pull/13505](https://togithub.com/firebase/firebase-ios-sdk/pull/13505) **Full Changelog**: firebase/firebase-ios-sdk@11.0.0...11.1.0 ### [`v11.0.0`](https://togithub.com/firebase/firebase-ios-sdk/releases/tag/11.0.0): Firebase Apple 11.0.0 [Compare Source](https://togithub.com/firebase/firebase-ios-sdk/compare/10.29.0...11.0.0) The Firebase Apple SDK (11.0.0) is now available. For more details, see the [Firebase Apple SDK release notes.](https://firebase.google.com/support/release-notes/ios#11.0.0) To install this SDK, see [Add Firebase to your project.](https://firebase.google.com/docs/ios/setup) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://togithub.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4xOC4xIiwidXBkYXRlZEluVmVyIjoiMzguNTIuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Co-authored-by: cgrindel-self-hosted-renovate[bot] <139595543+cgrindel-self-hosted-renovate[bot]@users.noreply.github.com>
Issue reproducible by changing unit test like so:
In the Objective-C implementation,
(nil, nil)
was being passed back bygetToken during timeouts.
firebase-ios-sdk/FirebaseAuth/Sources/SystemService/FIRAuthAPNSTokenManager.m
Lines 89 to 95 in eca84fd
This didn't cause issue though because the API calling getToken only checked for
the presence of a non-nil token:
firebase-ios-sdk/FirebaseAuth/Sources/AuthProvider/Phone/FIRPhoneAuthProvider.m
Lines 613 to 618 in eca84fd
In Swift though, the catch block will implicitly unwrap error, leading to the
crash when error is nil due to the timeout:
firebase-ios-sdk/FirebaseAuth/Sources/Swift/AuthProvider/PhoneAuthProvider.swift
Lines 320 to 326 in a5c253d
Since the error doesn't bubble up, how we handle this is an implementation
detail and I think we could either (1) remove the catch block and use
try?
,and trigger the catch block's code if the
try? await
results in nil. Or, (2)pass an error in the timeout case so a non-nil error is unwrapped. I think (2)
is more future proof so I went with that in this PR.
Fix #13470