RevenueCat / purchases-flutter

Flutter plugin for in-app purchases and subscriptions. Supports iOS, macOS and Android.
https://www.revenuecat.com/
MIT License
602 stars 168 forks source link

Crashes on iOS 17.3+ #1045

Open liri2006 opened 5 months ago

liri2006 commented 5 months ago

Environment

Crash report from the AppStore:

Date/Time:           2024-04-10 16:17:25.8544 +0100
Launch Time:         2024-04-07 17:11:53.6814 +0100
OS Version:          iPhone OS 17.3.1 (21D61)
Release Type:        User
Report Version:      104

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000019da1a3fc
Termination Reason: SIGNAL 5 Trace/BPT trap: 5
Terminating Process: exc handler [13594]

Triggered by Thread:  0

Thread 0 name:
Thread 0 Crashed:
0   libswiftCore.dylib              0x000000019da1a3fc _assertionFailure(_:_:file:line:flags:) + 264 (AssertCommon.swift:144)
1   PurchasesHybridCommon           0x0000000101727bcc closure #1 in variable initialization expression of static FatalErrorUtil.defaultFatalErrorClosure + 64 (FatalErrorUtil.swift:15)
2   PurchasesHybridCommon           0x000000010171fbb8 fatalError(_:file:line:) + 60 (FatalErrorUtil.swift:27)
3   PurchasesHybridCommon           0x000000010171fbb8 static CommonFunctionality.sharedInstance.getter + 84 (CommonFunctionality.swift:21)
4   PurchasesHybridCommon           0x000000010171fbb8 specialized static CommonFunctionality.logOut(completion:) + 352 (CommonFunctionality.swift:374)
5   PurchasesHybridCommon           0x000000010171c15c @objc static CommonFunctionality.restorePurchases(completion:) + 76
6   purchases_flutter               0x0000000101a82084 -[PurchasesFlutterPlugin logOutWithResult:] + 48 (PurchasesFlutterPlugin.m:320)
7   purchases_flutter               0x0000000101a809f0 -[PurchasesFlutterPlugin handleMethodCall:result:] + 1468 (PurchasesFlutterPlugin.m:89)
8   Flutter                         0x0000000104301a38  + -1 (:-1)
9   Flutter                         0x0000000103d63c00  + -1 (:-1)
10  libdispatch.dylib               0x00000001ac5a06a8 _dispatch_call_block_and_release + 32 (init.c:1530)
11  libdispatch.dylib               0x00000001ac5a2300 _dispatch_client_callout + 20 (object.m:561)
12  libdispatch.dylib               0x00000001ac5b0998 _dispatch_main_queue_drain + 984 (queue.c:7813)
13  libdispatch.dylib               0x00000001ac5b05b0 _dispatch_main_queue_callback_4CF + 44 (queue.c:7973)
14  CoreFoundation                  0x00000001a45dcf9c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 (CFRunLoop.c:1780)
15  CoreFoundation                  0x00000001a45d9ca8 __CFRunLoopRun + 1996 (CFRunLoop.c:3149)
16  CoreFoundation                  0x00000001a45d93f8 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
17  GraphicsServices                0x00000001e7b674f8 GSEventRunModal + 164 (GSEvent.c:2196)
18  UIKitCore                       0x00000001a69ff8a0 -[UIApplication _run] + 888 (UIApplication.m:3685)
19  UIKitCore                       0x00000001a69feedc UIApplicationMain + 340 (UIApplication.m:5270)
20  Runner                          0x00000001009de038 main + 80 (main.m:7)
21  dyld                            0x00000001c732edcc start + 2240 (dyldMain.cpp:1269)

Describe the bug

I've noticed that for the last few weeks App Store Connect started reporting increased number of crashes. I've checked the crash log and the main one is provided above. Is it possible to figure out what is causing those crashes from that log?

RCGitBot commented 5 months ago

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

liri2006 commented 4 months ago

Any thoughts on this? We still see few crashes a day even after updating to 6.26.0.

mshmoustafa commented 4 months ago

Hey @liri2006 looks like the issue is in logging out, can you share a code snippet of how you log out?

liri2006 commented 4 months ago

Hey @mshmoustafa, we are just calling await Purchases.logOut(); in the bloc event (together with some other cleanup stuff). Here is a full event code:

import 'package:fms/common/common.dart';
import 'package:purchases_flutter/purchases_flutter.dart';
import 'package:shared_preferences/shared_preferences.dart';

class Auth_LoggedOutEvent extends AuthEvent {
  @override
  Future<void> handle() async {
    bloc.snackBarService.showModalLoading();

    try {
      await Future.wait([
        bloc.authService.clearTokens(),
        bloc.localStorage.remove(AuthBloc.currentUserIdKey),
      ]);

      final prefs = await SharedPreferences.getInstance();
      await Future.wait([
        'language',
        ...FmsCacheKeys.clearable,
      ].map((x) => prefs.remove(x)));

      await AppHomeWidgetService.setExpireProductsWidget(
        <String, dynamic>{
          AppHomeWidgetSharedPreferencesKeys.isLoggedIn: false,
          AppHomeWidgetSharedPreferencesKeys.expiringProductsKey: null,
        },
        updateWidget: true,
      );

      await bloc.localNotificationsService.cancelAll();

      await bloc.fcmService.resetInstanceId();
      bloc.analyticsService.logLogout();
      await Purchases.logOut();
      await bloc.databaseService.clear();
      bloc.databaseService.close();
    } catch (e, st) {
      Log.ex(tag, e, st);
    } finally {
      AuthState.initial()
          .copyWith(
            localDocumentsPath: bloc.state.localDocumentsPath,
          )
          .emit(this);

      bloc.authService.setIsAuthenticated(false);
      bloc.snackBarService.hideModalLoading();
    }
  }
}
liri2006 commented 4 months ago

@mshmoustafa what do you think?

liri2006 commented 3 months ago

Any thoughts on what can cause this?