ably-flutter icon indicating copy to clipboard operation
ably-flutter copied to clipboard

PlatformException

Open TheManuz opened this issue 2 years ago • 7 comments

I'm getting these PlatformException reports in Firebase Crashlytics from ably_flutter package.

Stacktrace attached. com.atono.droppay_issue_651deded2d2148c2f3126a4ecfef5e5b_crash_session_6438ED7702140001717933A6E2DCBB88_DNE_0_v2_stacktrace.txt

┆Issue is synchronized with this Jira Bug by Unito

TheManuz avatar Apr 14 '23 07:04 TheManuz

➤ Automation for Jira commented:

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

sync-by-unito[bot] avatar Apr 14 '23 07:04 sync-by-unito[bot]

Hi @TheManuz, thanks for bringing this to our attention and providing the stack trace. For clarity, can you provide the versions of ably-flutter, Flutter, and Android where this exception is occurring?

mikelee638 avatar Apr 17 '23 18:04 mikelee638

Thanks for investigating the exception.

We have 59 reports of this crash on 35 users, with these specifics:

  • ably-flutter version 1.2.15
  • flutter version flutter: 3.7.9
  • Android versions
    • 73% Android 13
    • 22% Android 12
    • 2% Android 8
    • 2% Android 9
    • 1% Android 10
  • Devices
    • 92% Samsung
      • 22% Galaxy A71
      • 10% Galaxy S10+
      • 9% Galaxy S22
      • 51% Others
    • 5% Huawei
      • 2% Huawei Y6s
      • 2% Y7 Prime 2019
      • 1% P20 Pro
    • 3% Oppo
      • 3% Realme 7

I could also provide the stacktraces for all 59 exceptions, even if they're all pretty similar.

If you need them or other informations, feel free to ask.

TheManuz avatar Apr 18 '23 08:04 TheManuz

@TheManuz Would it be possible to provide some details on how you use this SDK please? especially in terms of anything related to threading. The log shows that network calls are happening on main thread which seems a bit strange as SDK should be executing network operations on a background thread

ikbalkaya avatar Apr 18 '23 12:04 ikbalkaya

Sure, this is the class that uses ably_flutter:

import 'package:ably_flutter/ably_flutter.dart';
import 'package:async/async.dart';
import 'package:my_app/core/logger.dart';
import 'package:my_app/notification/API/druid_notification.api.dart';
import 'package:my_app/notification/model/rtcManagers/rtc_manager.dart';

class AblyRtcManager extends RtcManager {
  final Realtime realtime;

  AblyRtcManager({
    required String token,
    required super.environment,
    required super.uuid,
  }) : realtime = Realtime(
          options: ClientOptions(
            key: token,
            authCallback: (TokenParams params) async {
              final result = await GetAblyRtcToken().consume();
              return result.data!["token"] as String;
            },
          ),
        );

  void _connectionStateListener(ConnectionStateChange stateChange) {
    logger.d('$runtimeType connection state: ${stateChange.current}');
  }

  @override
  Stream<Map<String, dynamic>> subscribeToAllChannels() {
    realtime.connection
        .on(ConnectionEvent.connected)
        .listen(_connectionStateListener);

    final streams = channels.map(
      (String channel) => realtime.channels.get(channel).subscribe(),
    );

    return StreamGroup.merge(streams).map(
      // Ably returns a Map<Object?, Object?>, must be converted
      (m) => Map<String, dynamic>.from(m.data as Map<Object?, Object?>),
    );
  }

  @override
  void unsubscribeToAllChannels() {
    void releaseChannel(channel) => realtime.channels.release(channel);
    channels.forEach(releaseChannel);
  }
}

You say that network calls are happening on the main thread, but I'm not sure I have control on this, since these network calls happen on the Android layer (which is handle by ably-flutter plugin), and not on the Flutter layer.

I hope that this these informations helps.

TheManuz avatar Apr 18 '23 13:04 TheManuz

Thanks @TheManuz That's really helpful. I will investigate this further later.

Just to be clear on network thread running on main thread, I don't think it's something to do with what you are doing. This is something that our SDK should handle.

ikbalkaya avatar Apr 18 '23 13:04 ikbalkaya

➤ Ikbal Kaya commented:

There is a MainThreadSink in Android plugin that runs everything on main thread and this issue happens when a connection fails (that is called in a background thread) and subsequently invokes a network call. (checkFallbackHosts). I don’t want to change this behaviour, since function execution from plugins to dart side (not yet sure) has to be done from main thread. It might be better for someone for a more knowledge on Flutter plugin look into this

sync-by-unito[bot] avatar Apr 28 '23 13:04 sync-by-unito[bot]