Skip to content

SIGSEGV crash in frame tracking on low-memory Android devices (globalEnv_CallObjectMethod) #3353

@JulianPscheid

Description

@JulianPscheid

Platform

Flutter Mobile Android

Obfuscation

Disabled

Debug Info

Disabled

Doctor

[✓] Flutter (Channel stable, 3.35.7, on macOS 26.1 25B78 darwin-arm64, locale en-US)
• Flutter version 3.35.7 on channel stable
• Dart version 3.9.2
• DevTools version 2.48.0

[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
• Platform android-36.1, build-tools 36.1.0
• Java version OpenJDK Runtime Environment (build 21.0.8+-14196175-b1038.72)

Version

9.8.0

Steps to Reproduce

  1. Deploy Flutter app with sentry_flutter: ^9.8.0 on low-memory Android devices (3-4GB RAM)
  2. Enable performance monitoring with default settings:
    await SentryFlutter.init((options) {
      options.tracesSampleRate = 1.0;
      options.profilesSampleRate = 1.0;
      // enableFramesTracking defaults to true
    });
  3. Run app on affected devices:
    - Samsung Galaxy Tab A7 (Android 12, 3GB RAM, MediaTek MT8768T)
    - itel S686LN (Android 15, 3-4GB RAM, UNISOC processor)
  4. Use app normally under memory pressure (multiple apps running, background processes)
  5. Crash occurs unpredictably during Flutter message loop processing

Key factors:

  • Only reproduces on low-end Android devices (3-4GB RAM)
  • Requires memory pressure (aggressive GC cycles)
  • Android 12-15 affected
  • Does not occur on high-end devices or other platforms

Expected Result

Sentry's frame tracking should safely invoke Window.onReportTimings callbacks without crashing, even under memory pressure on low-end Android devices.

Frame tracking metrics should be collected reliably, or the integration should gracefully handle callback lifecycle issues (e.g., check callback validity before invocation).

Actual Result

App crashes with SIGSEGV (Segmentation Fault) when Sentry's background thread attempts to invoke a stale Window.onReportTimings callback.

Stack Trace (Issue HEDY-AI-AZQ):
Thread: SentryExecutorServiceThreadFactory-0

flutter::Shell::ReportTimings::lambda::operator() (shell.cc:1633)
→ flutter::Engine::ReportTimings (engine.cc:301)
→ flutter::RuntimeController::ReportTimings (runtime_controller.cc:312)
→ flutter::PlatformConfiguration::ReportTimings (platform_configuration.cc:469)
→ tonic::DartInvoke (dart_invoke.cc:24)
→ Dart_InvokeClosure (dart_api_impl.cc:4710)
→ dart::DartEntry::InvokeFunction (dart_entry.cc:167)
→ globalEnv_CallObjectMethod () ← SIGSEGV HERE

Error Details:

  • Signal: SIGSEGV: Segfault
  • Thread: SentryExecutorServiceThreadFactory-0 (Sentry's background thread)
  • Mechanism: signalhandler
  • Handled: no (fatal crash)

Impact:

  • Production app crashes (16 users affected, 16 occurrences)
  • Only on low-memory Android devices
  • Started appearing in version with sentry_flutter 9.8.0

Root Cause Analysis:
Sentry's frame tracking registers a Dart callback with Flutter's Window.onReportTimings. On low-memory devices with aggressive GC:

  1. Sentry's background thread (SentryExecutorServiceThreadFactory-0) attempts to invoke the callback
  2. Under memory pressure, the Dart callback reference becomes stale/invalid
  3. JNI call (globalEnv_CallObjectMethod) attempts to access freed memory
  4. SIGSEGV crash occurs

Workaround:
Disable frame tracking on Android:

if (Platform.isAndroid) {
  options.enableFramesTracking = false;
  options.enableAutoPerformanceTracing = false;
}

This workaround eliminates the crash while preserving all error/crash reporting functionality.

### Are you willing to submit a PR?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions