Skip to content
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

withCheckedContinuation crashes on Xcode 16 RC #75952

Closed
MarkVillacampa opened this issue Aug 19, 2024 · 21 comments
Closed

withCheckedContinuation crashes on Xcode 16 RC #75952

MarkVillacampa opened this issue Aug 19, 2024 · 21 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels

Comments

@MarkVillacampa
Copy link

MarkVillacampa commented Aug 19, 2024

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: RevenueCat/purchases-ios#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

@MarkVillacampa MarkVillacampa added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels Aug 19, 2024
@MarkVillacampa
Copy link
Author

Quick update:

  • Crash is still reproducible in Xcode 16 beta 6.
  • The crash happens with withCheckedThrowingContinuation as well:
_ = try await withCheckedThrowingContinuation { continuation in
    continuation.resume(returning: true)
}

@mszyszylo
Copy link

mszyszylo commented Sep 3, 2024

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)

@MarkVillacampa MarkVillacampa changed the title withCheckedContinuation crashes on Xcode 16.1 beta 1 withCheckedContinuation crashes on Xcode 16 RC Sep 9, 2024
@MarkVillacampa
Copy link
Author

The crash is still present in Xcode 16 RC when running a Debug build as "Designed for iPad/iPhone" on macOS Sonoma

@random-yang
Copy link

Has anyone posted a question on the Apple Developer Forum, and is there a final solution to the problem?

@kiran-nayak-cheq
Copy link

+1. Any update on this?

@random-yang
Copy link

@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

@guidedways
Copy link

guidedways commented Sep 17, 2024

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.

@jshier
Copy link
Contributor

jshier commented Sep 21, 2024

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.

@sergiocampama
Copy link

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.

@tshortli
Copy link
Contributor

tshortli commented Sep 21, 2024

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.

@abdorizak
Copy link

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.

@guidedways
Copy link

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.

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.

@DougGregor
Copy link
Member

This was addressed in Swift 6.0.1.

@DougGregor
Copy link
Member

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.

@mike123789-dev
Copy link

This was addressed in Swift 6.0.1.

hi! in our project we are still using swift5
image

does this mean that the fix will not be applied while targeting swift5?

thanks in advance

@tshortli
Copy link
Contributor

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.

@mike123789-dev
Copy link

@tshortli
i was worried that we will have to migrate a whole codebase to swift 6.

thanks for the reply

@Lyine0924
Copy link

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.

@wingsofdoug
Copy link

wingsofdoug commented Dec 3, 2024

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.

@HoonHaChoi
Copy link

HoonHaChoi commented Dec 26, 2024

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)

@guidedways
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests