stripe-ios icon indicating copy to clipboard operation
stripe-ios copied to clipboard

[BUG] crash when calling `StripeAPI.deviceSupportsApplePay()`

Open davidweissler opened this issue 1 year ago • 4 comments

Summary

We're seeing crashes when calling StripeAPI.deviceSupportsApplePay()

Code to reproduce

The code is just a series of calls that ends with a call to StripeAPI.deviceSupportsApplePay()

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  	...
    AdNetworkHelper.reportAppOpenValue(sessionCount: count)
    ...
  }

  static func reportAppOpenValue(sessionCount: UInt) -> Int {
    let deviceSupportsApplePay = InAppProductManager.isStripeAvailable()
    ...
  }

  static func isStripeAvailable() -> Bool {
    return StripeAPI.deviceSupportsApplePay()
  }

iOS version

15.3.1 (19D52)

Installation method

SPM

SDK version

22.3.0

Other information

Example crash log

stripe_crash.txt

davidweissler avatar Jul 12 '22 18:07 davidweissler

That's an odd crash — it looks like this is an iPad Air 2, and the Secure Element isn't responding during the [PKPaymentAuthorizationController canMakePaymentsUsingNetworks:] call, which is causing the app to hang during launch and eventually be killed by the system watchdog.

This sounds like an Apple bug, so I think the only thing we can do is file a Feedback Assistant ticket. How many of these crashes are you seeing? Are you able to reproduce it on your own devices?

davidme-stripe avatar Jul 12 '22 18:07 davidme-stripe

In the last release of our app, it looks like there's about 30 devices crashing due to this.

CleanShot 2022-07-12 at 15 17 30@2x

I have tried a lot but have not been able to repro this myself unfortunately. And the crash occurs on varying devices, iPhones and iPads.

Edit to add: I guess I was also curious if other users have seen/reported this issue before, that you're aware of?

davidweissler avatar Jul 12 '22 19:07 davidweissler

Edit to add: I guess I was also curious if other users have seen/reported this issue before, that you're aware of?

I have not, and I can't find any references to similar issues online. 😞

One idea: Could you try dispatching reportAppOpenValue to run slightly after launch? Here's a wild guess of what might be happening:

  • StripeAPI.deviceSupportsApplePay queries [PKPaymentAuthorizationController canMakePaymentsUsingNetworks:] in PassKit.
  • PassKit's [PKInAppPaymentService secureElementStatus:] makes an XPC connection to passd (the Apple Pay daemon) from the main thread, requesting the status of the secure element.
  • passd blocks the XPC response while waiting for your app to finish launching. (I'm not sure why this would happen. Maybe PassKit would usually do some initialization with passd in a background thread at app launch, but it's racing with UIApplication.didFinishLaunchingWithOptions: on the main thread, which is why only some devices are crashing?)
  • But your app can't finish launching, because the main thread is blocked while waiting on [PKInAppPaymentService secureElementStatus:]. So passd never responds to the XPC request, and your app hangs until Frontboard kills the process.

davidme-stripe avatar Jul 12 '22 19:07 davidme-stripe

@davidme-stripe thanks for the suggestion! I was trying to see if some other code we might have been doing would cause the blocked thread. It might be a few weeks to test adding a delay in production, so let me know if it's ok to keep this issue open for a little bit and I can post an update here.

davidweissler avatar Jul 12 '22 21:07 davidweissler

@davidweissler closing this out for as stale, feel free to re-open if needed.

porter-stripe avatar Jan 10 '23 00:01 porter-stripe

@davidweissler Hi,Have you solved this problem? I also encountered the same problem

denggun avatar Oct 16 '23 08:10 denggun