RevenueCat / purchases-ios

In-app purchases and subscriptions made easy. Support for iOS, watchOS, tvOS, macOS, and visionOS.
https://www.revenuecat.com/
MIT License
2.3k stars 308 forks source link

Crash at launch Xcode 16 iOS 18 - EXC_BAD_ACCESS 0x100b63934 (0x100b638e0 + 84) specialized withCheckedContinuation<A>(isolation:function:_:) #4177

Open joaopdcgarcia opened 1 month ago

joaopdcgarcia commented 1 month ago

Describe the bug Crashes at launch with a not so useful stacktrace.

RevenueCat 4.43.2 Xcode 16 beta 5 + iOS 18 crash

  1. Environment
    1. Platform: iOS
    2. SDK version: 4.43.2.
    3. StoreKit version:
      • [x] StoreKit 1
      • [ ] StoreKit 2 (enabled with usesStoreKit2IfAvailable(true))
    4. OS version: 18
    5. Xcode version: 16 beta 5
    6. Device and/or simulator:
      • [x] Device
      • [ ] Simulator
    7. Environment:
      • [ ] Sandbox
      • [x] TestFlight
      • [ ] Production
    8. How widespread is the issue. Percentage of devices affected. 100%
  2. Debug logs that reproduce the issue.

No logs, just this stacktrace.

  1. Steps to reproduce, with a description of expected vs. actual behavior

Launch the app.

  1. Other information (e.g. stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc.)
<compiler-generated>
specialized withCheckedContinuation<A>(isolation:function:_:)

image

image

  1. Additional context Add any other context about the problem here.

We want to keep supporting iOS 12. Is the v.4.x of RevenueCat going to be deprecated?

RCGitBot commented 1 month ago

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

MarkVillacampa commented 1 month ago

Hello @joaopdcgarcia,

Is the issue only reproducing for you in TestFlight? do you have any more complete stacktrace? With just the one you posted we cannot be sure the crash happens within this SDK's code.

I've not been able to reproduce the issue you describe using Xcode 16.1 beta 2, a simulator running iOS 18.1, a device running iOS 18 beta 6, and version 4.32.2 of the SDK, while compiling in release mode.

joaopdcgarcia commented 1 month ago

Hello @joaopdcgarcia,

Is the issue only reproducing for you in TestFlight? do you have any more complete stacktrace? With just the one you posted we cannot be sure the crash happens within this SDK's code.

I've not been able to reproduce the issue you describe using Xcode 16.1 beta 2, a simulator running iOS 18.1, a device running iOS 18 beta 6, and version 4.32.2 of the SDK, while compiling in release mode.

One of our QA tester was the only one to reproduce this on TF (he has a lot of transactions not sure if that matters), consistently. If I comment out RevenueCat, it crashes again and that call seems to be done inside RC. I'm trying to gather logs by upgrading another device to iOS 18. EDIT: Not able to crash on this one either.

I've updated with the full stacktrace

image

We've built with xcode 16 beta 5.

rosday commented 1 month ago

I am suffering from a similar issue.

It happens when I try to build with Xcode on my own Mac as iOS app adapted to Mac. Other builds in simulators and real devices work fine

RevenueCat 5.2.3 XCode 16 beta 5 and XCode 16.1 beta MacOS Sonoma 14.5

Edit: Found out some users are having a crash in my Tesflight build, too, running iOS18.1

Tried commenting all my methods to check if I was doing something wrong, but simply calling Purchases.shared.offerings() also crashes the app

Screenshot 2024-08-16 at 11 02 27 Screenshot 2024-08-16 at 11 03 03
timothygremp commented 1 month ago

running xcode 16.1, swift package 5.2.3, issue occuring for me as well. This is line in debugger where dies after: DEBUG: ℹ️ Warming up intro eligibility cache for 2 products.

Where error throws:

static func call<Value, Error: Swift.Error>( method: (@escaping @Sendable (Result<Value, Error>) -> Void) -> Void ) async throws -> Value { return try await withCheckedThrowingContinuation { continuation in @Sendable func complete(_ result: Result<Value, Error>) { continuation.resume(with: result) }

        method(complete)
    }
}
MarkVillacampa commented 1 month ago

Thank you for the additional information @timothygremp @rosday @joaopdcgarcia

I have been able to reproduce the issue, but only in a very limited scenario.

The following snippet is enough to force the crash:

_ = await withCheckedContinuation { continuation in
    continuation.resume(returning: true)
}

I can reproduce on Xcode 16 beta 5 and Xcode 16.1 beta 1, 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.

I have not been able to test the scenario where it crashes when installed via TestFlight, but I'm confident it's triggered by the same bug.

Has any of you been able to reproduce the issue locally in a scenario that does not involve running as "Designed for iPhone/iPad"?

kristofferbv commented 1 month ago

Has any of you been able to reproduce the issue locally in a scenario that does not involve running as "Designed for iPhone/iPad"?

@MarkVillacampa, I’ve been facing a similar issue and can reproduce it on my iPhone running iOS 18 beta 4. The crash only occurs in Xcode 16.0 Beta 5.

image image
SAllen0400 commented 1 month ago

I'm also seeing a crash on withCheckedThrowingContinuation. I didn't experience this crash personally, but a member of my team is crashing on launch in Test Flight (They are on iOS 18 - beta 3).

I am running version 5.2.3 of the RevenueCat SDK. The minimum deployment target for my project is iOS 18.

Here's the stack trace and code snippet from the Test Flight crash report (again, I have not been able to recreate myself):

Screenshot 2024-08-19 at 11 02 49 AM Screenshot 2024-08-19 at 11 03 09 AM
rudrankriyam commented 1 month ago

It is fixed in Xcode 16 Beta 6!

rosday commented 1 month ago

It is fixed in Xcode 16 Beta 6!

It still crashes for me

MarkVillacampa commented 1 month ago

@rudrankriyam Unfortunately, I can still reproduce in Xcode 16 beta 6 by running the app in a Sonoma host as "Designed for iPhone/iPad". Can you confirm if it crashes for you in that scenario?

@SAllen0400 @kristofferbv you're both right, it also crashes in withCheckedThrowingContinuation. I will update issue report.

rudrankriyam commented 1 month ago

Hey @MarkVillacampa and @rosday, I updated my phone to iOS 18 Beta 7 too, and it is not crashing on it. Unfortunately, as you mentioned, it is crashing on other OSes, or previous betas. :/

MarkVillacampa commented 1 month ago

@rudrankriyam thanks for the clarification!

I have not been able to reproduce the crash on device by running from Xcode (I have not been able to test via TestFlight tho). If you're able to repro on device, could you describe the combination of Xcode and iOS versions?

rudrankriyam commented 1 month ago

@MarkVillacampa I was using Xcode 16 Beta 5 + iOS 18 Beta 6 where the crash was happening. I realised it when it started crashing on TestFlight where Xcode Cloud was using Beta 5. After updating to iOS 18 Beta 7 and Xcode 16 Beta 5, I am not seeing any withCheckedThrowingContinuation both for my code and RC's SDK

MarkVillacampa commented 1 week ago

Xcode 16 RC just came out and I am still able to reproduce the crash when running as "Designed for iPhone/iPad" on Sonoma.

I would like to know if anybody is still able to reproduce the issue when running the app in a different scenario (e.g. via TestFlight when running on iOS 17 or iOS 18 RC).

brendand commented 1 week ago

One of my TestFlight beta testers is getting a similar crash when running on macOS Sequoia public beta macOS 15.0 (24A5298h).

Was using RevenueCat 4.43.2. I've just updated to the main branch to see if that helps.

Thread 4 Crashed:
0   Tap Forms Pro                   0x000000010064e458 specialized withCheckedContinuation<A>(isolation:function:_:) + 40 (/<compiler-generated>:0)
1   Tap Forms Pro                   0x000000010064e458 specialized static Async.call<A>(method:) + 92 (AsyncExtensions.swift:105)
2   Tap Forms Pro                   0x000000010052871d closure #1 in CustomerInfoManager.getCustomerInfo(appUserID:isAppBackgrounded:completion:) + 1 (CustomerInfoManager.swift:352)
3   Tap Forms Pro                   0x00000001004caf39 partial apply for closure #1 in DefaultNetworkImageLoader.image(from:) + 1 (/<compiler-generated>:0)
4   Tap Forms Pro                   0x00000001004d360d specialized thunk for @escaping @isolated(any) @callee_guaranteed @async () -> (@out A) + 1 (/<compiler-generated>:0)
5   Tap Forms Pro                   0x00000001004cc65d partial apply for closure #1 in NSURLSession.data(from:) + 1
6   libswift_Concurrency.dylib      0x00000002627328a5 completeTaskWithClosure(swift::AsyncContext*, swift::SwiftError*) + 1 (Task.cpp:471)

He can no longer launch the app since it's calling into RevenueCat upon launch.

I know this is an iOS 18 thread, but thought I'd mention that it's also happening on macOS.

carloscabanero commented 1 week ago

Ran into this issue when we started testing iOS 18. Same as described under same conditions: Running on device, works under simulator, we can still reproduce running Xcode 16 RC and iOS 18 beta on devices. I couldn't reproduce when building on Xcode 15 and running on iOS 18.

A couple more notes in case it helps and our workaround:

Hope this helps.

rudrankriyam commented 1 week ago

From iOS 18 Beta 7, the issue is fixed from Apple side so hopefully the public release of iOS 18 will not have this issue. I still see crashes on TestFlight but from users who are using iOS 18 Beta 6 or below.

pewebapps commented 5 days ago

Is there going to be an update from RevenueCat on this? I pushed a new release out using the Xcode 16 RC without knowing this issue and have since experienced lots of crashes. For an indie developer, I don’t have QA’s etc and so I am disappointed that this issue wasn’t communicated to me and my fellow developers. A big problem like this makes me lose complete trust in RevenueCat.

dfed commented 3 days ago

I'm seeing this crash in Xcode 16 GM when targeting macOS 14.6.1 on a "built for iPad" app.

teeeeeegz commented 3 days ago

I am also experiencing this crash with users on iOS 18, compiled with Xcode 16 RC. However, I can't confirm whether those users are on an iOS 18 Beta.

CleanShot 2024-09-17 at 13 15 24@2x CleanShot 2024-09-17 at 13 14 12@2x

MilesV64 commented 3 days ago

I'm also experiencing this in production on iOS 18 compiled with Xcode 16 RC, this needs to be fixed ASAP. I see users on both iOS 18 and 18.1 affected.

cnordvik commented 2 days ago

We have 1900 crashes since iOS 18 launched with this error... at least 5 people say they are on the release of iOS 18 and it still crashes in our support inbox.

CleanShot 2024-09-17 at 18 43 24@2x

jeiting commented 2 days ago

Hey all, sorry we didn't have eyes on this until right now. We've got an incident going internally and should have some updates shortly.

jeiting commented 2 days ago

We're seeing this particular exception pop-up in the traces of a few other SDKs. It seems to be triggered by multiple SDKs.

https://github.com/airbnb/lottie-ios/issues/2472 https://github.com/aws-amplify/amplify-swift/issues/3806

We're trying to understand more and see if we can mitigate it with an SDK release. It's related to async / await, and reverting to using only the completion block methods might mitigate the issue.

aboedo commented 2 days ago

Hey folks, we're still digging into this.

We haven't been able to reproduce it locally, however.

In the past, we've only been able to produce in a very specific situation, which is running a combination of Xcode 16 beta, macOS apps designed for iPad, and debug builds. I realize that might not be the situation that's causing it for you.

As far as we can tell, the issue is caused by an underlying bug in Swift, triggered when calling withCheckedThrowingContinuation, which is what we use to bridge the gap between Swift Concurrency and completion blocks.

So there is a chance that you might avoid this crash by either:

However, since we haven't been able to reproduce yet, we can't assert that either of those is guaranteed to work.

@cnordvik or any of the folks in this thread, if you are seeing this in your crashlytics, would you be open to adding me to your account, or otherwise having a call with me to show me the details, so we can dig in deeper and figure this one out?

aboedo commented 2 days ago

Hey folks, we believe that https://github.com/RevenueCat/purchases-ios/pull/4286 might fix this. Could you give it a shot and let us know if it fixes the issue for you?

All you’d need to do is to update your SDK version to use the use-withUnsafeThrowingContinuation branch

minlite commented 2 days ago

I filed FB14768097 with Apple on August 12, 2024. It was this exact same bug when compiling with Xcode 16b5 and running on first iOS 18.1 Beta.

They never responded to me but it was fixed on the next iOS 18.1 beta, so I just assumed the patch would be applied on the iOS 18.0 train as well to make sure it's ready for launch. Looks like Apple actually forgot to apply the patch to 18.0 train and left it in prod.

Good news is that iOS 18.1 will be released in ~1.5 weeks and should fix it, but bad news is it's gonna make people not able to use Xcode 16 until then.

My initial bug report in amplify-swift repo

oryonatan commented 2 days ago

also see: EXC_BAD_ACCESS when running async code on "My Mac (Designed for iPad)" destination

aboedo commented 2 days ago

Looks like temporarily moving to withUnsafeContinuation and withUnsafeThrowingContinuation might do the trick. We've updated the #4286 to do that, if you wanna give it a shot

OlKir commented 1 day ago

Could this be connected with https://github.com/swiftlang/swift/issues/75771#issuecomment-2360469537 ? I can confirm that we also:

  1. Have crash reports related to withThrowingTaskGroup
  2. They started to appear before official iOS 18 release and happen only on iOS 18
  3. We can't reproduce them ourselves even with artificial heavy load multithreading scenarios
  4. In Xcode Organizer they are attributed to 22A5282m which is iOS beta
  5. Number of crashes has not significantly increased after iOS 18 public release (which was our biggest fear)
kgaidis commented 1 day ago

For more data points, my app had instant, repeating (5+ per user), withCheckedThrowingContinuation crashes when building off Xcode 16 (non-beta) for users. Had to do an emergency release with Xcode 15.4 and that seems to resolve it. It doesn't seem safe to use Xcode 16?

fire-at-will commented 1 day ago

@kgaidis Thanks for reporting!

For the app version that crashed for users, what version of the RevenueCat SDK was the app using? I'm curious if it contained the change in https://github.com/RevenueCat/purchases-ios/pull/4286 that migrated the SDK's calls from withCheckedThrowingContinuation to withUnsafeThrowingContinuation.

kgaidis commented 1 day ago

@fire-at-will 5.2.0 (not the newest), and note that I am not even sure its RevenueCat - I think this is just an overall iOS/Xcode 16 "crisis" where any use of this could be broken? I have a lot of my own code + other third-party SDK's. I am purely commenting to warn others that I am not sure if Xcode 16 is safe for anything.

emcro commented 1 day ago

I just had a report from a user with this same issue on my Catalyst update shipped with Xcode 16 RC, using RC v4.30.5.