Skip to content

fix(auth, functions): Xcode 26.4 'async let' cleanup crashes#15991

Merged
ncooke3 merged 17 commits intomainfrom
nc/fix-15974
Apr 1, 2026
Merged

fix(auth, functions): Xcode 26.4 'async let' cleanup crashes#15991
ncooke3 merged 17 commits intomainfrom
nc/fix-15974

Conversation

@ncooke3
Copy link
Copy Markdown
Member

@ncooke3 ncooke3 commented Mar 26, 2026

Tip

Recommend to review without whitespace changes: https://github.com/firebase/firebase-ios-sdk/pull/15991/changes?w=1

Local emulator testing

Test Case '-[FirebaseFunctionsIntegration.IntegrationTests testUnknownErrorAsync]' passed (0.012 seconds).
Test Suite 'IntegrationTests' passed at 2026-03-31 17:10:54.699.
	 Executed 51 tests, with 0 failures (0 unexpected) in 7.407 (7.425) seconds
Test Suite 'FirebaseFunctionsIntegration.xctest' passed at 2026-03-31 17:10:54.700.
	 Executed 51 tests, with 0 failures (0 unexpected) in 7.407 (7.425) seconds
Test Suite 'All tests' passed at 2026-03-31 17:10:54.700.
	 Executed 51 tests, with 0 failures (0 unexpected) in 7.407 (7.426) seconds
2026-03-31 17:10:54.984 xcodebuild[91020:874036] [MT] IDETestOperationsObserverDebug: 9.900 elapsed -- Testing started completed.
2026-03-31 17:10:54.984 xcodebuild[91020:874036] [MT] IDETestOperationsObserverDebug: 0.000 sec, +0.000 sec -- start
2026-03-31 17:10:54.984 xcodebuild[91020:874036] [MT] IDETestOperationsObserverDebug: 9.900 sec, +9.900 sec -- end

Test session results, code coverage, and logs:
	/Users/nickcooke/Library/Developer/Xcode/DerivedData/firebase-ios-sdk-anxqgakbhyqozfhbkutiwmcpphvm/Logs/Test/Test-FirebaseFunctionsIntegration-2026.03.31_17-10-35--0400.xcresult

** TEST SUCCEEDED **

nickcooke@nickcooke-mac2 firebase-ios-sdk (nc/fix-15974) % git pull origin nc/fix-15974
From github.com:firebase/firebase-ios-sdk
 * branch                nc/fix-15974 -> FETCH_HEAD
Already up to date.
nickcooke@nickcooke-mac2 firebase-ios-sdk (nc/fix-15974) % xcode-select -p
/Applications/Xcode_26.4.app/Contents/Developer

Fix #15974

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

@ncooke3
Copy link
Copy Markdown
Member Author

ncooke3 commented Mar 26, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ncooke3
Copy link
Copy Markdown
Member Author

ncooke3 commented Mar 26, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

shanemhamilton added a commit to shanemhamilton/firebase-ios-sdk that referenced this pull request Mar 28, 2026
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>
vadimf added a commit to vadimf/firebase-ios-sdk that referenced this pull request Mar 29, 2026
…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
@ncooke3
Copy link
Copy Markdown
Member Author

ncooke3 commented Mar 31, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ncooke3
Copy link
Copy Markdown
Member Author

ncooke3 commented Mar 31, 2026

/gemini review

@ncooke3 ncooke3 marked this pull request as ready for review March 31, 2026 20:08
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ncooke3 and others added 2 commits March 31, 2026 16:09
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>
@ncooke3
Copy link
Copy Markdown
Member Author

ncooke3 commented Mar 31, 2026

/gemini review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ncooke3
Copy link
Copy Markdown
Member Author

ncooke3 commented Mar 31, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@ncooke3
Copy link
Copy Markdown
Member Author

ncooke3 commented Mar 31, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ncooke3 ncooke3 merged commit db5828b into main Apr 1, 2026
193 of 202 checks passed
@ncooke3 ncooke3 deleted the nc/fix-15974 branch April 1, 2026 00:57
@ncooke3
Copy link
Copy Markdown
Member Author

ncooke3 commented Apr 1, 2026

Hi @mikehardy, fwiw, I couldn't reproduce the issue with Auth. For one, the async lets used it are for async ObjC APIs. Perhaps the interop layer triggers a different compiler reaction? So, I tried to wrap these calls in Swift methods (much like Functions does). Still couldn't reproduce the crash. I did pin it down to the 2 AppCheck related async lets in Functions. Disable either and Functions works, even with the async let for the Auth token call.

In any case, this "fix" shouldn't hurt Auth and I've decided to check it in anyhow to be preventative.

@mikehardy
Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Functions] Release build crash in HTTPSCallable.call() due to Swift 6.3 async let compiler bug

3 participants