Skip to content
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

Transactions are very slow to complete when started inside appRunner, block the UI from showing up #2233

Closed
maBarabas opened this issue Aug 14, 2024 · 2 comments · Fixed by #2266
Assignees

Comments

@maBarabas
Copy link
Contributor

Platform

Flutter Mobile

Obfuscation

Disabled

Debug Info

Disabled

Doctor

`flutter doctor -v`
[✓] Flutter (Channel stable, 3.22.3, on macOS 14.6 23G80 darwin-arm64, locale en-GB)
    • Flutter version 3.22.3 on channel stable at /Users/barabas/src/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b0850beeb2 (4 weeks ago), 2024-07-16 21:43:41 -0700
    • Engine revision 235db911ba
    • Dart version 3.4.4
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /Users/barabas/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = /Users/barabas/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2024.1)
    • 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 17.0.11+0-17.0.11b1207.24-11852314)

[✓] Connected device (4 available)
    • Pixel 5 (mobile)                • 0C221FDD4003LH            • android-arm64 • Android 13 (API 33)
    • iPhone XR (mobile)              • 00008020-001E2C881A33002E • ios           • iOS 16.5.1 20F75
    • macOS (desktop)                 • macos                     • darwin-arm64  • macOS 14.6 23G80 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin        • macOS 14.6 23G80 darwin-arm64

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Version

8.7.0

Steps to Reproduce

Run this app on iOS or android in profile mode (using a real DSN):

Future<void> main() async {
  await SentryFlutter.init(
    (options) {
      options
        ..dsn =
            '<snip>'
        ..tracesSampleRate = 1.0;
    },
    appRunner: appMain,
  );
}

Future<void> appMain() async {
  final transaction = Sentry.startTransaction('hello', 'hello');
  await transaction.finish();

  runApp(MyApp());
}

Expected Result

App UI appears almost instantly after app is launched.

Actual Result

The UI appears after about 10s.

Rerun without the tracesSamplerate or without the dsn or without the transaction or with Sentry before and notice that the UI appears in less than a second. Removing just one of these is enough to avoid the bug.

I bisected on android and the first slow commit is 5e7abc5, where the app UI never appears.

Are you willing to submit a PR?

No

@buenaflor
Copy link
Contributor

hey, thanks for the issue, we'll have a look!

@buenaflor buenaflor moved this from Needs Discussion to Needs Investigation in Mobile & Cross Platform SDK Aug 19, 2024
@denrase
Copy link
Collaborator

denrase commented Aug 27, 2024

@maBarabas The issue is that you are awaiting finishing the transaction before runApp is beeing called.

You have two options here:

  • Move the transaction after runApp:
Future<void> appMain() async {
  runApp(MyApp());

  final transaction = Sentry.startTransaction('hello', 'hello');
  await transaction.finish();
}
  • Finish the transaction after runApp:
Future<void> appMain() async {
  final transaction = Sentry.startTransaction('hello', 'hello');
  
  // .. do stuff

  final endTime = DateTime.now();
  
  runApp(MyApp());

  await transaction.finish(endTimestamp: endTime);
}

In the case you mentioned one of our event processors ins running into a timeout, because the PostFrameCallback is not being called when runApp was not executed before.

@buenaflor buenaflor moved this from Needs Investigation to Needs More Information in Mobile & Cross Platform SDK Aug 29, 2024
@getsantry getsantry bot moved this to Waiting for: Community in GitHub Issues with 👀 3 Sep 12, 2024
@github-project-automation github-project-automation bot moved this from Needs More Information to Done in Mobile & Cross Platform SDK Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants