withCheckedContinuation crashes on Xcode 16 RC
Description
I can reproduce on Xcode 16 RC and Xcode 16.1 beta, but ONLY when running the app as "Designed for iPhone/iPad" on macOS Sonoma, and ONLY in debug mode (crash goes away in release mode).
I cannot reproduce by running on iOS 17 or 18 neither device nor simulator, and cannot reproduce either when running on macOS Sequoia beta.
Some developers have reported the issue also reproduces when installing the app via TestFlight on an iOS 18 device.
Original issue: https://github.com/RevenueCat/purchases-ios/issues/4177
FB14855530
Reproduction
_ = try await withCheckedContinuation { continuation in
continuation.resume(returning: true)
}
Stack dump
Thread 0 Crashed:
0 asdfsadf.debug.dylib 0x102551354 withCheckedContinuation<A>(isolation:function:_:) + 232
1 asdfsadf.debug.dylib 0x102551135 closure #1 in closure #2 in ContentView.body.getter + 1 (ContentView.swift:21)
2 asdfsadf.debug.dylib 0x102552299 partial apply for closure #1 in closure #2 in ContentView.body.getter + 1
3 libswift_Concurrency.dylib 0x2548aa0f9 completeTaskWithClosure(swift::AsyncContext*, swift::SwiftError*) + 1
Expected behavior
It doesnt crash
Environment
Xcode 16.1 beta 1
Apple Swift version 6.0 (swiftlang-6.0.0.7.6 clang-1600.0.24.1) Target: arm64-apple-macosx14.0
Additional information
No response
Quick update:
- Crash is still reproducible in Xcode 16 beta 6.
- The crash happens with
withCheckedThrowingContinuationas well:
_ = try await withCheckedThrowingContinuation { continuation in
continuation.resume(returning: true)
}
Same issue for me.
I'm on Xcode 16.1 beta.
App crashes like @MarkVillacampa described with only iOS 18 simulators.
Thread 1: EXC_BAD_ACCESS (code=1, address=0x4)
The crash is still present in Xcode 16 RC when running a Debug build as "Designed for iPad/iPhone" on macOS Sonoma
Has anyone posted a question on the Apple Developer Forum, and is there a final solution to the problem?
+1. Any update on this?
@kiran-nayak-cheq Looks like the issue has been fixed in the updated version? https://developer.apple.com/forums/thread/761580 https://forums.developer.apple.com/forums/thread/762682?page=1#803104022
We're seeing this for our publicly released apps using Xcode version 16.0 (16A242d) (published, final updates to App Store, not debug versions) where random users are seeing persistent crashes at launch and the stack traces are vague. We see the following in each of them though:
9 libswift_Concurrency.dylib 0x26737e8a5 completeTaskWithClosure(swift::AsyncContext*, swift::SwiftError*) + 1
We are personally unable to reproduce this in any environment (debug / release) or on any OS. The users experiencing this range from being on macOS 11 to macOS 15, and iOS 16 / 18. It could potentially be affecting all operating system versions but we are unable to say this with certainty. We are using Xcode 16 to compile our apps using Swift v5 (5.10, not 6). The last update posted from Xcode 15 does not exhibit this issue.
We're seeing something similar in Alamofire, but in withTaskCancellationHandler that wraps withCheckedContinuation. Switching to unsafe continuations or the deprecated vision of withTaskCancellationHandler had no effect.
We saw similar things on our app but we were able to identify it only happening on iOS 18/macOS 15 betas that were before the RC builds for each platform. We've found 3 cases of users where this was fixed by updating to the actual RC builds for each platform.
We did not see this happening before iOS 18/macOS 15.
On iOS the crashes looked like SIGSEV 4 with the following line as the top stack. On macOS they looked like the signal in this report (maybe because it's on the simulator it matches the macOS crash signature)
‘‘‘ @_swiftmacro_7Copilot0022Controllersswift_tiAIefMX24_33_9isolationfMf.swift - Line 1 ‘‘‘
I was not able to find this generated file anywhere.
This is a known issue documented in the Xcode 16 release notes (search for 134793410). It was addressed on the release/6.0.1 branch here: [6.0.1] SILOptimizer: Allow inlining of transparent functions in @backDeployed thunks by tshortli · Pull Request #76218 · swiftlang/swift · GitHub. Designed for iPhone/iPad binaries built with debug optimizations and deployed to macOS Sonoma or earlier are affected.
I'm facing the same Thread 1: EXC_BAD_ACCESS (code=1, address=0x4) issue with Xcode Version 16.0 and iOS 18.0, but it only occurs on specific devices and isn't consistently reproducible. this crash seems to depend on the specific device or scenario. It would be great if this could be investigated further to understand the underlying cause and ensure stability.
I'm using Swift 5 with Xcode 16. Below is a sample code to demonstrate the issue:
import Alamofire
import Foundation
struct MyModel: Decodable {
let id: Int
let name: String
}
func fetchData() async -> Result<MyModel, Error> {
return await AF.request("https://api.example.com/data")
.response(MyModel.self)
}
extension DataRequest {
@MainActor
func response<T: Decodable>(_ t: T.Type) async -> Result<T, Error> {
return await withCheckedContinuation { continuation in // Fails on here `EXC_BAD_ACCESS error`
responseData(queue: .main) { response in
switch response.result {
case .success(let data):
do {
let decoder = JSONDecoder()
let obj = try decoder.decode(t.self, from: data)
continuation.resume(returning: .success(obj))
} catch {
continuation.resume(returning: .failure(error))
}
case .failure(let error):
continuation.resume(returning: .failure(error))
}
}
}
}
}
The crash occurs when navigating between screens while the API call is still in progress, which leads to an EXC_BAD_ACCESS error. This only seems to happen on specific devices running iOS 18.0, and it's not consistently reproducible.
I'm facing the same Thread 1:
EXC_BAD_ACCESS (code=1, address=0x4)issue with Xcode Version 16.0 and iOS 18.0, but it only occurs on specific devices and isn't consistently reproducible. this crash seems to depend on the specific device or scenario. It would be great if this could be investigated further to understand the underlying cause and ensure stability.I'm using Swift 5 with Xcode 16. Below is a sample code to demonstrate the issue:
import Alamofire import Foundation struct MyModel: Decodable { let id: Int let name: String } func fetchData() async -> Result<MyModel, Error> { return await AF.request("https://api.example.com/data") .response(MyModel.self) } extension DataRequest { @MainActor func response<T: Decodable>(_ t: T.Type) async -> Result<T, Error> { return await withCheckedContinuation { continuation in // Fails on here `EXC_BAD_ACCESS error` responseData(queue: .main) { response in switch response.result { case .success(let data): do { let decoder = JSONDecoder() let obj = try decoder.decode(t.self, from: data) continuation.resume(returning: .success(obj)) } catch { continuation.resume(returning: .failure(error)) } case .failure(let error): continuation.resume(returning: .failure(error)) } } } } }The crash occurs when navigating between screens while the API call is still in progress, which leads to an
EXC_BAD_ACCESS error. This only seems to happen on specific devices runningiOS 18.0, and it's not consistently reproducible.
Check with these users, they are most likely on an older beta version of iOS 18. I can confirm all our users were on an older beta version and updating to the latest iOS version fixed these crashes for them.
This was addressed in Swift 6.0.1.
There is a similar issue that affects older iOS 18 betas. Those devices should really be updated to the iOS 18 release (or newer), but if you need an app-side workaround, see https://forums.swift.org/t/global-with-concurrency-functions-crash-on-catalyst-designed-for-ipad-on-macos/74823/13.
This was addressed in Swift 6.0.1.
hi! in our project we are still using swift5
does this mean that the fix will not be applied while targeting swift5?
thanks in advance
No, this is a common source of confusion but the setting you have screenshot is the Swift "language mode". The language mode is independent of the version of the Swift compiler you are building with. Swift 6.0.1 refers to the version of the compiler.
@tshortli i was worried that we will have to migrate a whole codebase to swift 6.
thanks for the reply
hello. I am still experiencing the same issue. Is anyone else having the same problem as me? I deployed the app in the following environment
Environment
Xcode-16.1(16B40) swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4) Target: arm64-apple-macosx14.0
I have not been able to reproduce the crash in apps built on my local Mac, but it seems to happen in apps uploaded to the app store.
I have just updated to: MacOS: 15.1.1 (24B91) Xcode: Version 16.1 (16B40) swift --version produces: swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4) IOS-18.0 sims crash. IOS-18.1 and 17.2 simulators do not crash
This is specifically when building for development.
For what its worth a coworker building the same application with these same versions does not cause the same crash.
Edit, This is for Rosetta Simulators.
Hello, I've been struggling with the same problem recently. Could you please let me know the iOS version where the problem occurred?
The problem only occurs in apps distributed through the App Store.
Issue iOS version is 18.0.0
Environment
xcode 16.1(16B40) swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4) Target: arm64-apple-macosx15.0(24A335)
@HoonHaChoi you should ask the users of your app to upgrade their iOS version to the latest. They're most likely (read: for sure) on one of the earlier beta versions with the issue. This is no longer an issue with 18 RC or above.
A crash previously occurred related to this issue.
However, with the following combination, the crash does not occur.
Has the issue been fixed?
- macOS Sequoria 15.3.1
- Xcode 16.3 Beta
- Simulator iPhone 16 Pro + OS 18.4