fix(auth, functions): Xcode 26.4 'async let' cleanup crashes#15991
fix(auth, functions): Xcode 26.4 'async let' cleanup crashes#15991
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request replaces async let usage with explicit Task blocks in FirebaseAuth and FirebaseFunctions to work around a Swift 6.3 regression in Xcode 26.4 that causes release-build crashes during async let teardown. While the implementation correctly addresses the regression, a critical issue was identified in FunctionsContext.swift where the try keyword is misplaced before a non-throwing initializer; it should instead specifically precede the throwing expression await authToken.value to ensure successful compilation and correct error handling.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request replaces async let with unstructured Task blocks in FirebaseAuth and FirebaseFunctions to work around a Swift 6.3 regression in Xcode 26.4 that causes release-build crashes. The review feedback highlights that this change results in the loss of automatic task cancellation propagation and suggests using withTaskCancellationHandler to restore the original behavior and improve the robustness of the workaround.
Swift 6.3 compiler regression (swiftlang/swift#87481) generates incorrect LIFO deallocation ordering for async-let stack frames. This causes swift_task_dealloc crashes in Release builds on physical iOS devices. Replace `async let` bindings with explicit `Task {}` objects in: - FunctionsContext.swift (3 bindings → 3 Tasks) - AuthBackend.swift (2 bindings → 2 Tasks) Matches firebase/firebase-ios-sdk PR firebase#15991 targeting 12.12.0. Temporary fork patch until upstream fix ships. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…wiftlang/swift#87481) Backport of firebase#15991 to 12.11.0. Fixes SIGABRT: freed pointer was not the last allocation in release builds. Changes: - FunctionsContext.swift: 3 async let -> Task {} + .value - AuthBackend.swift: 2 async let -> Task {} + .value
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request replaces the use of async let with a Task-based approach and withTaskCancellationHandler in both FirebaseAuth and FirebaseFunctions to mitigate a Swift regression causing crashes during teardown. The review feedback identifies an invalid await try syntax that needs to be corrected to try await and points out several version number typos (Xcode 26.4 and Swift 6.3) in the comments and changelogs that should be updated to reflect the correct versions.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request replaces async let with explicit Task management and withTaskCancellationHandler in FirebaseAuth and FirebaseFunctions to resolve a crash occurring with Xcode 16.4. The review feedback identifies several version number typos in the changelogs and source code comments that need correction. Additionally, an improvement was suggested for FunctionsContext.swift to use a defer block within the task handler to ensure that background tasks are properly cancelled if an error is thrown during execution, preventing potential resource leaks.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Since authToken.value can throw, an error will cause the operation block to exit early. Unlike async let, unstructured Tasks are not automatically cancelled when they go out of scope. This could lead to appCheckToken and limitedUseAppCheckToken continuing to run in the background if authToken fails.
Adding a defer block to cancel the tasks ensures they are cleaned up regardless of whether the function succeeds or throws.
Also, a task can be canceled more than once with no ill effects.
Sources:
There was a problem hiding this comment.
Code Review
This pull request replaces the use of async let with explicit Task objects and withTaskCancellationHandler in FirebaseAuth and FirebaseFunctions to work around a Swift 6.0 regression in Xcode 16.2 that caused crashes during teardown in release builds. The feedback identifies several typos in the CHANGELOG files and source code comments where the Xcode and Swift versions were incorrectly listed as 26.4 and 6.3, respectively, and provides suggestions to correct them to 16.2 and 6.0.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request replaces async let with explicit Task management and withTaskCancellationHandler in AuthBackend.swift and FunctionsContext.swift to resolve a release-build crash caused by a Swift compiler regression. The review feedback identifies typos in the Xcode and Swift version numbers cited in the CHANGELOGs and source code. Additionally, a code suggestion was provided to use a defer block in AuthBackend.swift to ensure tasks are cancelled, maintaining consistency with other implementations in the PR.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request addresses a release-build crash occurring in Xcode 26.4 (Swift 6.3) caused by a regression in async let teardown. The fix replaces async let with explicit Task instances and withTaskCancellationHandler in both FirebaseAuth and FirebaseFunctions to ensure proper resource cleanup. Review feedback suggests minor refinements for clarity, including moving the await keyword closer to the asynchronous property access in AuthBackend.swift and updating an outdated comment regarding error handling in FunctionsContext.swift.
|
Hi @mikehardy, fwiw, I couldn't reproduce the issue with Auth. For one, the In any case, this "fix" shouldn't hurt Auth and I've decided to check it in anyhow to be preventative. |
|
Interesting - thanks for the note there @ncooke3 , I reworded my placeholder issue over in react-native-firebase-land - hopefully doesn't affect too many folks before your workaround here makes it to release, it's been strangely quiet over there whereas I was expecting it to be a hot topic, so seems like your fix here is still out in front of most people's release build pipelines |
Tip
Recommend to review without whitespace changes: https://github.com/firebase/firebase-ios-sdk/pull/15991/changes?w=1
Local emulator testing
Fix #15974