-
Notifications
You must be signed in to change notification settings - Fork 28.4k
[in_app_purchase] StoreKit2 error logs about using a platform channel from a native thread #166493
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
Comments
Thanks for the report @edpizzi, I tried to follow this by using both these approaches, but I wasn't able to replicate the reported error after trying to purchase it few times. Maybe I am missing some steps / config to properly verify it, that I'll try to see if I can get it working to replicate properly. Meantime, I'll keep the issue open and label for team's attention on the reported behavior and error triggered. |
I did a bit more investigating. I edited the code to print whether we're in the main thread when sending transaction update messages back to Flutter (flutter/packages@be9a9b9). What I find is the following (launched from XCode): if I make a purchase, the transaction update sends from the main thread (safe). When I refund a purchase (XCode UI) or verify purchases nontrivally (example app UI, but only if there are purchases to trigger the callback), I see the update come from a non-main thread (unsafe):
Looking at the code, we create a Task to listen for transaction updates. My iOS dev is weak, but I understand that the queue / thread a task is assigned to depends on the context. If these tasks are assigned to a background queue, then this would be unsafe without jumping back to the main thread to send to the channel. If I set a debugger when this happens via restorePurchases, I see we're in a thread for a So I don't know why it's not consistently reproducible (although this line will only get logged in debug builds), but the problem and the fix seem pretty clear. Here's a basic fix: All of my debugging can be found in this branch: https://github.com/edpizzi/flutter-packages/tree/repro-sk2-threading I'm happy to clean this up into a PR if this is a reasonable approach, or let the team address it. Just mentioning #116383, the main bug tracking adding StoreKit2 support, so that these are linked. |
Steps to reproduce
8f5844af8135a61becd731981c000b00814facc4
)packages/in_app_purchase/in_app_purchase/example
app to work with StoreKit in XCode, so products appear in the iOS simulator in dev builds.main()
to enable StoreKit 2 (snippet below). Ensure that "Using StoreKit 2" is logged.Alternative path to reproduce:
4a. Launch from XCode. Purchase the "Upgrade", then refund it in XCode's Transactions log. Restart and repeat as necessary. The error is logged just after the refund is issued.
Expected results
(no error logs about thread safety)
Actual results
I get the same log line, whether triggered from restore purchases or on StoreKit Test refund:
This seems like it could be a severe error, so I'm reluctant to ignore it and launch with SK2 enabled unless maintainers are confident that this is not something that is likely to result in crashes. (I have not observed crashes, just this error message, but I'm testing on just one device.)
I observe the same error logs in a real iOS app, only when I enable SK2 (also tested using StoreKit Test). Reporting since SK1 is deprecated.
Code sample
Enabling storekit2 in the in_app_purchase example app
Screenshots or Video
No response
Logs
Logs
Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: