ably / ably-flutter

A wrapper around our Cocoa and Java client library SDKs, providing iOS and Android support for those using Flutter and Dart.
https://ably.com/download
Apache License 2.0
60 stars 16 forks source link

Realtime connection with authUrl causes crash on iOS #465

Closed motiapp closed 1 year ago

motiapp commented 1 year ago

This basic connection code causes a fatal crash of my iOS app every time that connect() is called on an ably.Realtime instance. I have tried turning off autoConnect and manually connecting, and it crashes either way. It happens every time on both the Simulator and a iPhone X device. When running on the simulator I get a crash report in a system dialog window (not from flutter's console).

My connection code is basic and works just fine on the Android simulator.


final headers = {
  HttpHeaders.authorizationHeader: "Bearer $accessToken",
  HttpHeaders.contentTypeHeader: "application/json",
  HttpHeaders.acceptLanguageHeader: Platform.localeName,
};
final options = ably.ClientOptions(
  authUrl: Urls.ablyAuthUrl,
  authHeaders: headers,
  echoMessages: false,
);
final realtime = ably.Realtime(options: options);
log("Ably connection state: ${_realtime?.connection.state}");
realtime?.connection.on().listen((stateChange) {
  log("Ably connection state changed: ${stateChange.event}");
  final isConnected = stateChange.event == ably.ConnectionEvent.connected;
});

Does this even work on iOS for anyone right now?

iOS app crash log:


-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Incident Identifier: 4CE4E757-6E44-4DC4-B86B-46B3DC44AEFC
CrashReporter Key:   51B41356-FD63-BD11-3BAF-7A9FA60DACDB
Hardware Model:      MacBookPro18,2
Process:             Runner [60368]
Path:                /Users/USER/Library/Developer/CoreSimulator/Devices/1200B6F6-D6A1-4074-92BE-8D8869AD7211/data/Containers/Bundle/Application/BC25DC43-6B0D-4A92-8CAF-2CB9446F4771/Runner.app/Runner
Identifier:          com.***********
Version:             4.2.3 (65)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd_sim [98415]
Coalition:           com.apple.CoreSimulator.SimDevice.1200B6F6-D6A1-4074-92BE-8D8869AD7211 [236917]
Responsible Process: SimulatorTrampoline [14671]

Date/Time:           2023-04-29 04:04:37.7352 -0400
Launch Time:         2023-04-29 04:04:22.5390 -0400
OS Version:          macOS 13.2.1 (22D68)
Release Type:        User
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread:  0

Last Exception Backtrace:
0   CoreFoundation                         0x180437324 __exceptionPreprocess + 160
1   libobjc.A.dylib                        0x180051274 objc_exception_throw + 56
2   CoreFoundation                         0x180445e3c +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3   CoreFoundation                         0x18043b224 ___forwarding___ + 1308
4   CoreFoundation                         0x18043d50c _CF_forwarding_prep_0 + 92
5   CoreFoundation                         0x1803fc3d0 CFURLCopyAbsoluteURL + 68
6   CoreFoundation                         0x18042e364 _CFURLComponentsCreateWithURL + 28
7   Foundation                             0x180bc6f18 -[__NSConcreteURLComponents initWithURL:resolvingAgainstBaseURL:] + 112
8   Foundation                             0x180bc8d84 +[NSURLComponents componentsWithURL:resolvingAgainstBaseURL:] + 36
9   Ably                                   0x100c09994 -[ARTAuthInternal buildURL:withParams:] + 140 (ARTAuth.m:218)
10  Ably                                   0x100c09d10 -[ARTAuthInternal buildRequest:withParams:] + 108 (ARTAuth.m:246)
11  Ably                                   0x100c0ae88 -[ARTAuthInternal _requestToken:withOptions:callback:] + 700 (ARTAuth.m:355)
12  Ably                                   0x100c0dc94 -[ARTAuthInternal _authorize:options:callback:] + 908 (ARTAuth.m:562)
13  Ably                                   0x100c59e70 -[ARTRealtimeInternal transportConnectForcingNewToken:newConnection:] + 1268 (ARTRealtime.m:1015)
14  Ably                                   0x100c564ac -[ARTRealtimeInternal transitionSideEffects:] + 1256 (ARTRealtime.m:566)
15  Ably                                   0x100c55c7c -[ARTRealtimeInternal transition:withErrorInfo:] + 388 (ARTRealtime.m:486)
16  Ably                                   0x100c55aec -[ARTRealtimeInternal transition:] + 44 (ARTRealtime.m:477)
17  Ably                                   0x100c54ef4 -[ARTRealtimeInternal _connect] + 120 (ARTRealtime.m:392)
18  Ably                                   0x100c54e70 __30-[ARTRealtimeInternal connect]_block_invoke + 36 (ARTRealtime.m:383)
19  libdispatch.dylib                      0x180134708 _dispatch_client_callout + 16
20  libdispatch.dylib                      0x180144ec4 _dispatch_lane_barrier_sync_invoke_and_complete + 92
21  Ably                                   0x100c54e34 -[ARTRealtimeInternal connect] + 124 (ARTRealtime.m:381)
22  Ably                                   0x100c53394 -[ARTRealtime connect] + 36 (ARTRealtime.m:152)
23  ably_flutter                           0x102c5a708 _connectRealtime_block_invoke_20 + 232 (AblyFlutter.m:287)
24  ably_flutter                           0x102c5f760 -[AblyFlutter handleMethodCall:result:] + 504 (AblyFlutter.m:784)
25  Flutter                                0x112a72958 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 112
26  Flutter                                0x1124ca814 invocation function for block in flutter::PlatformMessageHandlerIos::HandlePlatformMessage(std::_LIBCPP_ABI_NAMESPACE::unique_ptr >) + 108
27  libdispatch.dylib                      0x180132ee4 _dispatch_call_block_and_release + 24
28  libdispatch.dylib                      0x180134708 _dispatch_client_callout + 16
29  libdispatch.dylib                      0x180143fd8 _dispatch_main_queue_drain + 1220
30  libdispatch.dylib                      0x180143b04 _dispatch_main_queue_callback_4CF + 40
31  CoreFoundation                         0x18039a784 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
32  CoreFoundation                         0x180394de4 __CFRunLoopRun + 1912
33  CoreFoundation                         0x180394254 CFRunLoopRunSpecific + 584
34  GraphicsServices                       0x188eb7c9c GSEventRunModal + 160
35  UIKitCore                              0x10ce3eff0 -[UIApplication _run] + 868
36  UIKitCore                              0x10ce42f3c UIApplicationMain + 124
37  Runner                                 0x10037b814 main + 64 (AppDelegate.swift:5)
38  dyld_sim                               0x1007e5514 start_sim + 20
39  dyld                                   0x100965e50 start + 2544
40  ???                             0x9a6b000000000000 ???
sync-by-unito[bot] commented 1 year ago

➤ Automation for Jira commented:

The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3562

ikbalkaya commented 1 year ago

Hey @motiapp Thanks for reporting this. Could you please confirm that this started happening after upgrading your ably-flutter version to 1.2.16? If so can I suggest that you downgrade to 1.2.15 until we fix this issue?

motiapp commented 1 year ago

I hadn't used the package before last week. I did try the .15 version also, just to make sure, and it was the same for me.

ikbalkaya commented 1 year ago

Thanks for confirming @motiapp .

The issue has been identified and we will provide a fix as soon as possible. In the meantime, can I suggest that you use authCallback instead of authUrl in your ClientOptions For example

 final options = ClientOptions(
    authHeaders: headers,
    echoMessages: false,
      authCallback: (params) async {
        // Replace this with your token request, token string, JWT, or  tokenDetails object
        return TokenRequest.fromMap(
          await AppProvisioning().getTokenRequest(),
        );
      }
  );

Please do not forget to remove authUrl

motiapp commented 1 year ago

Thanks, I can confirm it's working with the authCallback method.

ikbalkaya commented 1 year ago

This is currently partially blocked by https://github.com/ably/ably-java/issues/935