flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [FirebasePerformance] java.lang.IllegalArgumentException: Object for handle already exists: 3

Open KamleshArya opened this issue 2 years ago • 25 comments

Bug report

Describe the bug After integration of the firebase performance flutter plugin, I am continuously seeing the exception.

:"PlatformException","value":"PlatformException(error, Object for handle already exists: 3, null, java.lang.IllegalArgumentException: Object for handle already exists: 3\n\tat io.flutter.plugins.firebaseperformance.FirebasePerformancePlugin.addHandler(FirebasePerformancePlugin.java:48) Screenshot 2021-12-05 at 12 03 21 PM

I am using firebase_performance: ^0.7.1+5 and followed the documentation as given.

Implemented code:

HttpMetric _metric =
    FirebasePerformance.instance.newHttpMetric(API_URI, HttpMethod.Get);

try{
_metric = FirebasePerformance.instance.newHttpMetric(
                            options.uri.toString(), HttpMethod.Get),
                        FirebasePerformance.instance
                            .isPerformanceCollectionEnabled()
                            .then((value) => {
                                  if (!value)
                                    FirebasePerformance.instance
                                        .setPerformanceCollectionEnabled(true)
                                }),
                        _metric.start()
}
finally {
      if (isMobile) _metric.stop();
    }


KamleshArya avatar Dec 05 '21 06:12 KamleshArya

@KamleshArya Can you provide flutter doctor -v, flutter pub deps -- --style=compact, the entire log in text format instead of in screenshots along with steps to replicate that leads to this exception. Thanks.

darshankawar avatar Dec 06 '21 11:12 darshankawar

@darshankawar

flutter doctor -v response:

[✓] Flutter (Channel stable, 2.5.3, on macOS 12.0.1 21A559 darwin-x64, locale en-IN) • Flutter version 2.5.3 at /Users/kamlesh/Desktop/Projects/Yellowstrips/flutter • Upstream repository [email protected]:flutter/flutter.git • Framework revision 18116933e7 (8 weeks ago), 2021-10-15 10:46:35 -0700 • Engine revision d3ea636dc5 • Dart version 2.14.4

[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0-rc1) • Android SDK at /Users/kamlesh/Library/Android/sdk • Platform android-31, build-tools 32.0.0-rc1 • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165) • All Android licenses accepted.

[✗] Xcode - develop for iOS and macOS ✗ Xcode installation is incomplete; a full installation is necessary for iOS development. Download at: https://developer.apple.com/xcode/download/ Or install Xcode via the App Store. Once installed, run: sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer sudo xcodebuild -runFirstLaunch ✗ CocoaPods not installed. CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side. Without CocoaPods, plugins will not work on iOS or macOS. For more info, see https://flutter.dev/platform-plugins To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[✓] VS Code (version 1.62.3) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.29.0

[✓] Connected device (1 available) • Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.93


flutter pub deps -- --style=compact Response:

Dart SDK 2.14.4 Flutter SDK 2.5.3 yellowstrips_app 1.0.1+1

dependencies:

  • animated_text_kit 4.2.1 [flutter characters]
  • cached_network_image 3.2.0 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web]
  • carousel_slider 4.0.0 [flutter]
  • connectivity_plus 2.1.0 [flutter connectivity_plus_platform_interface connectivity_plus_linux connectivity_plus_macos connectivity_plus_web connectivity_plus_windows]
  • cupertino_icons 1.0.4
  • dio 4.0.4 [http_parser path]
  • dio_cache_interceptor 3.0.3 [dio path uuid]
  • dio_http2_adapter 2.0.0 [http2 dio]
  • firebase_analytics 8.3.4 [firebase_analytics_platform_interface firebase_analytics_web firebase_core flutter meta]
  • firebase_core 1.10.3 [firebase_core_platform_interface firebase_core_web flutter meta]
  • firebase_crashlytics 2.4.1 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]
  • firebase_performance 0.7.1+5 [firebase_core firebase_core_platform_interface firebase_performance_platform_interface firebase_performance_web flutter]
  • flag 5.0.1 [flutter flutter_svg enum_to_string]
  • flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
  • flutter_branch_sdk 3.5.0 [flutter flutter_web_plugins plugin_platform_interface js]
  • flutter_facebook_auth 3.5.6+3 [flutter flutter_facebook_auth_platform_interface flutter_facebook_auth_web]
  • flutter_reaction_button 2.0.0+1 [flutter]
  • flutter_secure_storage 5.0.2 [meta flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows]
  • flutter_staggered_animations 1.0.0 [flutter]
  • flutter_typeahead 3.2.3 [flutter flutter_keyboard_visibility]
  • font_awesome_flutter 9.2.0 [flutter]
  • get_it 7.2.0 [async collection]
  • google_fonts 2.1.0 [flutter http path_provider crypto]
  • google_mobile_ads 1.0.1 [meta flutter]
  • google_sign_in 5.2.1 [flutter google_sign_in_platform_interface google_sign_in_web meta]
  • http 0.13.4 [async http_parser meta path]
  • intl 0.17.0 [clock path]
  • nb_utils 4.4.10 [flutter shared_preferences fluttertoast connectivity_plus]
  • provider 6.0.1 [collection flutter nested]
  • sentry_flutter 6.2.0 [flutter flutter_web_plugins sentry package_info_plus]
  • shared_preferences 2.0.9 [flutter meta shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
  • truecaller_sdk 0.0.4 [flutter]
  • url_launcher 6.0.17 [flutter meta url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]

dev dependencies:

  • flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]

transitive dependencies:

  • args 2.3.0
  • async 2.8.1 [collection meta]
  • boolean_selector 2.1.0 [source_span string_scanner]
  • cached_network_image_platform_interface 1.0.0 [flutter flutter_cache_manager]
  • cached_network_image_web 1.0.1 [flutter flutter_cache_manager cached_network_image_platform_interface]
  • characters 1.1.0
  • charcode 1.3.1
  • clock 1.1.0
  • collection 1.15.0
  • connectivity_plus_linux 1.1.1 [flutter connectivity_plus_platform_interface meta nm]
  • connectivity_plus_macos 1.2.1 [connectivity_plus_platform_interface flutter]
  • connectivity_plus_platform_interface 1.1.1 [flutter meta plugin_platform_interface]
  • connectivity_plus_web 1.1.0+1 [connectivity_plus_platform_interface flutter_web_plugins flutter]
  • connectivity_plus_windows 1.2.0 [connectivity_plus_platform_interface flutter]
  • crypto 3.0.1 [collection typed_data]
  • dbus 0.6.6 [args ffi meta xml]
  • enum_to_string 2.0.1
  • fake_async 1.2.0 [clock collection]
  • ffi 1.1.2
  • file 6.1.2 [meta path]
  • firebase 9.0.2 [http http_parser js]
  • firebase_analytics_platform_interface 2.0.1 [flutter meta]
  • firebase_analytics_web 0.3.0+1 [firebase firebase_analytics_platform_interface flutter flutter_web_plugins meta]
  • firebase_core_platform_interface 4.2.0 [collection flutter meta plugin_platform_interface]
  • firebase_core_web 1.5.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
  • firebase_crashlytics_platform_interface 3.1.8 [collection firebase_core flutter meta plugin_platform_interface]
  • firebase_performance_platform_interface 0.0.1+8 [firebase_core flutter plugin_platform_interface]
  • firebase_performance_web 0.0.3+1 [firebase firebase_core firebase_core_web firebase_performance_platform_interface flutter flutter_web_plugins]
  • flutter_blurhash 0.6.0 [flutter meta pedantic]
  • flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid]
  • flutter_facebook_auth_platform_interface 2.7.0 [flutter plugin_platform_interface]
  • flutter_facebook_auth_web 2.6.0+2 [flutter flutter_web_plugins js flutter_facebook_auth_platform_interface]
  • flutter_keyboard_visibility 5.1.0 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_web flutter]
  • flutter_keyboard_visibility_platform_interface 2.0.0 [flutter meta plugin_platform_interface]
  • flutter_keyboard_visibility_web 2.0.0 [flutter_keyboard_visibility_platform_interface flutter_web_plugins flutter]
  • flutter_secure_storage_linux 1.1.0 [flutter flutter_secure_storage_platform_interface]
  • flutter_secure_storage_macos 1.1.0 [flutter flutter_secure_storage_platform_interface]
  • flutter_secure_storage_platform_interface 1.0.0 [flutter plugin_platform_interface]
  • flutter_secure_storage_web 1.0.2 [flutter flutter_web_plugins flutter_secure_storage_platform_interface js]
  • flutter_secure_storage_windows 1.1.2 [flutter flutter_secure_storage_platform_interface]
  • flutter_svg 0.22.0 [flutter meta path_drawing vector_math xml]
  • flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
  • fluttertoast 8.0.8 [flutter flutter_web_plugins]
  • google_sign_in_platform_interface 2.1.0 [flutter meta quiver]
  • google_sign_in_web 0.10.0+3 [flutter flutter_web_plugins google_sign_in_platform_interface js meta]
  • http2 2.0.0
  • http_parser 4.0.0 [charcode collection source_span string_scanner typed_data]
  • js 0.6.3
  • matcher 0.12.10 [stack_trace]
  • meta 1.7.0
  • nested 1.0.0 [flutter]
  • nm 0.4.1 [dbus]
  • octo_image 1.0.1 [flutter flutter_blurhash]
  • package_info_plus 1.3.0 [flutter package_info_plus_platform_interface package_info_plus_linux package_info_plus_macos package_info_plus_windows package_info_plus_web]
  • package_info_plus_linux 1.0.3 [package_info_plus_platform_interface flutter path]
  • package_info_plus_macos 1.3.0 [flutter]
  • package_info_plus_platform_interface 1.0.2 [flutter meta plugin_platform_interface]
  • package_info_plus_web 1.0.4 [flutter flutter_web_plugins http meta package_info_plus_platform_interface]
  • package_info_plus_windows 1.0.4 [package_info_plus_platform_interface ffi flutter win32]
  • path 1.8.0
  • path_drawing 0.5.1+1 [vector_math meta path_parsing flutter]
  • path_parsing 0.2.1 [vector_math meta]
  • path_provider 2.0.7 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
  • path_provider_android 2.0.9 [flutter path_provider_platform_interface]
  • path_provider_ios 2.0.7 [flutter path_provider_platform_interface]
  • path_provider_linux 2.1.2 [flutter path path_provider_platform_interface xdg_directories]
  • path_provider_macos 2.0.4 [flutter meta path_provider_platform_interface]
  • path_provider_platform_interface 2.0.1 [flutter meta platform plugin_platform_interface]
  • path_provider_windows 2.0.4 [ffi flutter meta path path_provider_platform_interface win32]
  • pedantic 1.11.1
  • petitparser 4.4.0 [meta]
  • platform 3.1.0
  • plugin_platform_interface 2.0.2 [meta]
  • process 4.2.4 [file path platform]
  • quiver 3.0.1+1 [matcher]
  • rxdart 0.27.3
  • sentry 6.2.0 [http meta stack_trace uuid]
  • shared_preferences_android 2.0.9 [flutter meta shared_preferences_platform_interface]
  • shared_preferences_ios 2.0.8 [flutter meta shared_preferences_platform_interface]
  • shared_preferences_linux 2.0.3 [file flutter meta path path_provider_linux shared_preferences_platform_interface]
  • shared_preferences_macos 2.0.2 [flutter shared_preferences_platform_interface]
  • shared_preferences_platform_interface 2.0.0 [flutter]
  • shared_preferences_web 2.0.2 [flutter flutter_web_plugins meta shared_preferences_platform_interface]
  • shared_preferences_windows 2.0.3 [file flutter meta path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
  • sky_engine 0.0.99
  • source_span 1.8.1 [collection path term_glyph]
  • sqflite 2.0.1 [flutter sqflite_common path]
  • sqflite_common 2.0.1+1 [synchronized path meta]
  • stack_trace 1.10.0 [path]
  • stream_channel 2.1.0 [async]
  • string_scanner 1.1.0 [charcode source_span]
  • synchronized 3.0.0
  • term_glyph 1.2.0
  • test_api 0.4.2 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
  • typed_data 1.3.0 [collection]
  • url_launcher_android 6.0.13 [flutter meta url_launcher_platform_interface]
  • url_launcher_ios 6.0.13 [flutter meta url_launcher_platform_interface]
  • url_launcher_linux 2.0.2 [flutter]
  • url_launcher_macos 2.0.2 [flutter]
  • url_launcher_platform_interface 2.0.4 [flutter plugin_platform_interface]
  • url_launcher_web 2.0.5 [flutter flutter_web_plugins meta url_launcher_platform_interface]
  • url_launcher_windows 2.0.2 [flutter]
  • uuid 3.0.5 [crypto]
  • vector_math 2.1.0
  • win32 2.3.1 [ffi]
  • xdg_directories 0.2.0 [meta path process]
  • xml 5.3.1 [collection meta petitparser]

KamleshArya avatar Dec 08 '21 12:12 KamleshArya

Please can you try the latest firebase_performance plugin version since this should now be fixed.

Salakar avatar Dec 08 '21 21:12 Salakar

@KamleshArya See above comment and per it, try using latest performance plugin and see if it resolves the issue.

darshankawar avatar Dec 09 '21 10:12 darshankawar

@darshankawar @Salakar

The issue still persists.

I tried with firebase_performance: ^0.8.0+2

Steps to reproduce:

  1. Integrate the plugin as per the documentation
  2. Switch tabs or move to a different link in the flutter app and it will start throwing this exception.

Stack trace: E/MethodChannel#plugins.flutter.io/firebase_performance(32348): Failed to handle method call E/MethodChannel#plugins.flutter.io/firebase_performance(32348): java.lang.IllegalArgumentException: Object for handle already exists: 4

I can see that it's a common issue for a lot of users:

  1. https://stackoverflow.com/questions/69332209/flutter-is-showing-unhandled-exception-platformexceptionerror-object-for-han
  2. https://github.com/FirebaseExtended/flutterfire/issues/7417

KamleshArya avatar Dec 09 '21 13:12 KamleshArya

I tried the official plugin example (latest) on latest master but didn't notice the exception as mentioned, so I am going to label it based on the report above, for further investigation.

darshankawar avatar Dec 13 '21 12:12 darshankawar

For me, this issue only happens during hot reload.

If I click the green button in VSCode to restart, everything is fine. As soon as I hot reload by saving a file, it re-renders the app and perhaps eventually it creates two traces with an identical name.

I ended up wrapping it in a try ... ignore and linked to this issue.

ciriousjoker avatar Jan 09 '22 05:01 ciriousjoker

Facing the exact same issue - but like @CiriousJoker , it only happens when hot reloading. I'm also using the latest version of the plugin

onalenna-monare avatar Jan 19 '22 11:01 onalenna-monare

New trace handles are created using:

  @override
  TracePlatform newTrace(String name) {
    final int traceHandle = _nextHandle++;
    return MethodChannelTrace(_handle, traceHandle, name);
  }

while _nextHandle is a:

  static int _nextHandle = 0;

I would assume a hot restart will reset the _nextHandle to 0 in the dart code, but the native side will not reset the handles?

hpoul avatar Jan 30 '22 10:01 hpoul

FYI: This crash also happens when you simply call start() on the same Trace two times.. like

    final Trace trace = _performance.newTrace('test_trace_3');
    await trace.start();
    await trace.start();

https://github.com/FirebaseExtended/flutterfire/blob/9976d9d66b870143227b08af068da3bc2efc5411/packages/firebase_performance/firebase_performance_platform_interface/lib/src/method_channel/method_channel_trace.dart#L26-L28

I guess this could be improved to also check for _hasStarted 🤔️ Although to me this is still a bit confusing, since it isn't really documented that a Trace can't be reused (I thought it could be, until reading the code).

It's also unclear to me if two traces of the same name can be started at the same time? Would something like this work:

    final Trace trace1 = _performance.newTrace('test_trace');
    await trace1.start();
    final Trace trace2 = _performance.newTrace('test_trace');
    await trace2.start();
    await trace1.stop();
    await trace2.stop();

hpoul avatar Mar 02 '22 14:03 hpoul

Also encountering this issue in the latest release (when hot reloading), so on 0.8.0^5

jessegeens avatar Mar 06 '22 13:03 jessegeens

We are experiencing the same on 0.8.0+7. After hot restarting and starting a trace (which we do with http tracing), the app just crashes (for me on iOS). Nothing there to catch. Very unfortunate.

@hpoul your example to start two separate traces with the same 'name' seems to work.

ma-pe avatar Mar 19 '22 11:03 ma-pe

@ma-pe yes, with the same 'name' does not throw an error, but reusing the same Trace object does.

This code fails (last I checked):

    final Trace trace = _performance.newTrace('test_trace_3');
    await trace.start();
    await trace.start();

hpoul avatar Mar 19 '22 14:03 hpoul

Same issue here

klausjakobsen avatar Mar 23 '22 09:03 klausjakobsen

I was able to figure out what made the app crash on iOS only.

Future<void> someMethod() async {
   Trace trace = FirebasePerformance.instance.newTrace('almostfriday');
   try {
      trace.start()
      int numberOfBeers = await api.getFridayBeerCountInFridge();
      trace.stop();
   } catch (e) {
      print(e);
   }
}

If the api call failed and we tried to call someMedthod() again, trace.start() was called again without trace.stop() which made the app crash. In this example it would have made sense to have trace.stop(); in the catch method as well.

Conclusion: Make sure to stop whatever trace you start or face fatal crash in your iOS app.

I suggest in the method handler in the iOS code for [FirebasePerformance] we add a check if the trace is already running if not at least update the documentation or have a proper error message to the dev, right now it dies in the first line in appdelegate <3

klausjakobsen avatar Mar 23 '22 12:03 klausjakobsen

Here is a repro using a stripped down version of the example:

  1. Run app
  2. Hit Run Trace One button
  3. Hot Restart
  4. Hit Run Trace One button again
  5. Error Object for handle already exists: 1
Sample Code
import 'dart:async';
import 'dart:io';

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_performance/firebase_performance.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class DefaultFirebaseConfig {
  static FirebaseOptions get platformOptions {
    if (kIsWeb) {
      return const FirebaseOptions(
        apiKey: 'AIzaSyAgUhHU8wSJgO5MVNy95tMT07NEjzMOfz0',
        authDomain: 'react-native-firebase-testing.firebaseapp.com',
        databaseURL: 'https://react-native-firebase-testing.firebaseio.com',
        projectId: 'react-native-firebase-testing',
        storageBucket: 'react-native-firebase-testing.appspot.com',
        messagingSenderId: '448618578101',
        appId: '1:448618578101:web:772d484dc9eb15e9ac3efc',
        measurementId: 'G-0N1G9FLDZE',
      );
    } else if (Platform.isIOS || Platform.isMacOS) {
      return const FirebaseOptions(
        appId: '1:448618578101:ios:2bc5c1fe2ec336f8ac3efc',
        apiKey: 'AIzaSyAHAsf51D0A407EklG1bs-5wA7EbyfNFg0',
        projectId: 'react-native-firebase-testing',
        messagingSenderId: '448618578101',
        iosBundleId: 'io.flutter.plugins.firebase.firestore.example',
        iosClientId: '448618578101-ja1be10uicsa2dvss16gh4hkqks0vq61.apps.googleusercontent.com',
        androidClientId: '448618578101-2baveavh8bvs2famsa5r8t77fe1nrcn6.apps.googleusercontent.com',
        storageBucket: 'react-native-firebase-testing.appspot.com',
        databaseURL: 'https://react-native-firebase-testing.firebaseio.com',
      );
    } else {
      return const FirebaseOptions(
        appId: '1:448618578101:android:3ad281c0067ccf97ac3efc',
        apiKey: 'AIzaSyCuu4tbv9CwwTudNOweMNstzZHIDBhgJxA',
        projectId: 'react-native-firebase-testing',
        messagingSenderId: '448618578101',
      );
    }
  }
}

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(options: DefaultFirebaseConfig.platformOptions, name: 'NOT_DEFAULT');
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  void _testTrace1() {
    final Trace trace = FirebasePerformance.instance.newTrace('test_trace_3');
    trace.start();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Firebase Performance Example'),
        ),
        body: Center(
          child: ElevatedButton(
            onPressed: _testTrace1,
            child: const Text('Run Trace One'),
          ),
        ),
      ),
    );
  }
}

kulture-rob-snider avatar Apr 06 '22 18:04 kulture-rob-snider

Facing exactly the same issue image

tech-andgar avatar Apr 18 '22 01:04 tech-andgar

me too

vimaxwell avatar Apr 21 '22 06:04 vimaxwell

This issue seems to persist when a second HttpMetric is being created for the same URL without the first one being stopped.

hellyab avatar Apr 27 '22 21:04 hellyab

This issue still persist in 0.8.0+13

carlosfiori avatar Jun 10 '22 15:06 carlosfiori

Is there any update on this?

Ibtesam-Mahmood avatar Jun 16 '22 05:06 Ibtesam-Mahmood

I can confirm that this error still happens on firebase_performance: ^0.8.0+14 , but only if you don't call stop.

rwrz avatar Jun 29 '22 10:06 rwrz

Hi, I have the same issue, but it is interesting if I use the following code from documentation, all is good and I don't get any issue and will see the custom trace in Performance Dashboard.

firebase_performance: ^0.8.0+13

Trace customTrace = FirebasePerformance.instance.newTrace('custom-trace');
await customTrace.start();
// Code you want to trace
await customTrace.stop();

But only if I replace the Trace customTrace with final customTrace, it fails! So this code fails:

final customTrace = FirebasePerformance.instance.newTrace('custom-trace');
await customTrace.start();
// Code you want to trace
await customTrace.stop();

I called both codes inside a button's onPressed.

rafoolin avatar Jun 30 '22 13:06 rafoolin

I initialized 2 traces with different names on 2 different class properties. Called start on the constructor and I am calling the stop on a callback function, this means my traces are not stopped on the same scope. This causes the same exception "Object for handle already exist".

This doesn't happen as long as I run just one trace at the time. Feels like a quite important feature to start more than one trace and call stop when async or callback functions finishes.

carlosfvp avatar Jul 12 '22 15:07 carlosfvp

Every time I hot restart my app this error happens. I tried to handle the error using try/ catch so it doesn't interfere the other parts of the process. I found out it happens when we call

await trace?.start();

The error on Android is always:

E/MethodChannel#plugins.flutter.io/firebase_performance(18567): Failed to handle method call
E/MethodChannel#plugins.flutter.io/firebase_performance(18567): java.lang.IllegalArgumentException: Object for handle already exists: 1
E/MethodChannel#plugins.flutter.io/firebase_performance(18567): 	at io.flutter.plugins.firebase.performance.FlutterFirebasePerformancePlugin.addHandler(FlutterFirebasePerformancePlugin.java:54)
E/MethodChannel#plugins.flutter.io/firebase_performance(18567): 	at io.flutter.plugins.firebase.performance.FlutterFirebasePerformance.newTrace(FlutterFirebasePerformance.java:85)
E/MethodChannel#plugins.flutter.io/firebase_performance(18567): 	at io.flutter.plugins.firebase.performance.FlutterFirebasePerformance.onMethodCall(FlutterFirebasePerformance.java:57)
E/MethodChannel#plugins.flutter.io/firebase_performance(18567): 	at io.flutter.plugins.firebase.performance.FlutterFirebasePerformancePlugin.onMethodCall(FlutterFirebasePerformancePlugin.java:79)
E/MethodChannel#plugins.flutter.io/firebase_performance(18567): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#plugins.flutter.io/firebase_performance(18567): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#plugins.flutter.io/firebase_performance(18567): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#plugins.flutter.io/firebase_performance(18567): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#plugins.flutter.io/firebase_performance(18567): 	at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#plugins.flutter.io/firebase_performance(18567): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#plugins.flutter.io/firebase_performance(18567): 	at android.os.Looper.loop(Looper.java:246)
E/MethodChannel#plugins.flutter.io/firebase_performance(18567): 	at android.app.ActivityThread.main(ActivityThread.java:8653)
E/MethodChannel#plugins.flutter.io/firebase_performance(18567): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_performance(18567): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
E/MethodChannel#plugins.flutter.io/firebase_performance(18567): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

The number is not fixed. I mean it changes for each error. There should be either a way for us to check if this object handle exists or it determines this thing within the plugin code.

At the moment I'm using:

  firebase_performance: 0.8.2+1
My flutter doctor
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-x64, locale en-US)
    • Flutter version 3.0.5 at /Users/lvlrx/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f1875d570e (13 days ago), 2022-07-13 11:24:16 -0700
    • Engine revision e85ea0e79c
    • Dart version 2.17.6
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
    • Android SDK at /Users/lvlrx/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0-rc4
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.69.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
    • SM A705FN (mobile) • R58M72K6A2D • android-arm64  • Android 11 (API 30)
    • macOS (desktop)    • macos       • darwin-x64     • macOS 12.4 21F79 darwin-x64
    • Chrome (web)       • chrome      • web-javascript • Google Chrome 101.0.4951.64

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

After I put try/catch blocks around these parts of code, it doesn't crash on iOS at least. However, the error is still logged on Android devices.

lvlrSajjad avatar Jul 26 '22 08:07 lvlrSajjad

Using this version 0.7.1+5 avoids the log 🤔

danielgomezrico avatar Sep 06 '22 20:09 danielgomezrico