Skip to content

[Due for payment 2026-08-05] [$250] [Sentry: APP-7WP] HybridApp iOS EXC_BAD_ACCESS in SentryFramesTracker #95197

Closed

Description

@mountiny

Sentry

https://expensify.sentry.io/issues/APP-7WP

Impact (snapshot at filing)

  • Users (total since first seen): 92
  • Events: 101
  • Users (last 7d): 18
  • Events (last 7d): 18
  • First seen: 2026-03-18
  • Last seen: 2026-07-02 (ongoing)
  • Platform: iOS HybridApp
  • App version(s): 9.4.23
  • Affected route(s): navigation (ttid-navigation span active)
  • Mechanism: mach (EXC_BAD_ACCESS)

Stack trace (top frames, first-party only)

SentryFramesTracker.displayLinkCallback
SentryFramesTracker.reportNewFrame
RNSentryFramesTrackerListener framesTrackerHasNewFrame
RNSentryTimeToDisplay putTimeToInitialDisplayForActiveSpan
NSString stringByAppendingString

Suspected cause

EXC_BAD_ACCESS in Sentry RN SDK frames tracker during time-to-display measurement on navigation, possibly a use-after-free when appending span identifiers.

Reproduction

Unknown — see Sentry events linked from the Sentry issue.

Related

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Jul 2, 2026
  2. self-assigned this
    on Jul 2, 2026
  3. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jul 2, 2026
  4. KJ21-ENG commented on Jul 2, 2026

    @KJ21-ENG
    Contributor

    Proposal

    What is the root cause of that problem?

    The app enables Sentry React Navigation time-to-initial-display measurement in the shared navigation integration. That integration is included in the native Sentry setup and then registered with the root NavigationContainer, so HybridApp iOS navigation activates the Sentry RN native TTID frame tracker shown in the crash stack (RNSentryTimeToDisplay, RNSentryFramesTrackerListener, SentryFramesTracker).

    const navigationIntegration = Sentry.reactNavigationIntegration({
    enableTimeToInitialDisplay: true,
    });

    const integrations = [navigationIntegration, tracingIntegration, browserProfilingIntegration, breadcrumbsIntegration, consoleIntegration, reportingObserverIntegration].filter(
    (integration): integration is NonNullable<typeof integration> => integration !== undefined,
    );
    Sentry.init({
    dsn: CONFIG.SENTRY_DSN,
    // In development, debugTransport replaces the default Sentry transport.
    // When "Send data to Sentry" toggle is ON, it forwards envelopes to Sentry via fetch.
    // When the toggle is OFF, it silently discards envelopes (returns 200 noop).
    // When "Log Sentry to console" toggle is ON, it logs envelope contents to the console.
    transport: isDevelopment() ? makeDebugTransport : undefined,
    tracesSampleRate: 1.0,
    enableAutoPerformanceTracing: true,
    enableUserInteractionTracing: true,
    integrations,

    const onReadyWithSentry = useCallback(() => {
    endSpan(CONST.TELEMETRY.SPAN_NAVIGATION_ROOT_READY);
    endSpan(CONST.TELEMETRY.SPAN_BOOTSPLASH.NAVIGATION);
    onReady();
    navigationIntegration.registerNavigationContainer(navigationRef);
    setupNavigationFocusReturn();

    The app is pinned to @sentry/react-native / RNSentry 8.2.0 and native iOS Sentry 9.5.1, so this App-side option is opting that SDK into the exact native frame-tracker path that is crashing during iOS navigation.

    "@sentry/react-native": "8.2.0",

    App/ios/Podfile.lock

    Lines 4077 to 4104 in a9e6aed

    - RNSentry (8.2.0):
    - boost
    - DoubleConversion
    - fast_float
    - fmt
    - glog
    - hermes-engine
    - RCT-Folly
    - RCT-Folly/Fabric
    - RCTRequired
    - RCTTypeSafety
    - React-Core
    - React-debug
    - React-Fabric
    - React-featureflags
    - React-graphics
    - React-hermes
    - React-ImageManager
    - React-jsi
    - React-NativeModulesApple
    - React-RCTFabric
    - React-renderercss
    - React-rendererdebug
    - React-utils
    - ReactCodegen
    - ReactCommon/turbomodule/bridging
    - ReactCommon/turbomodule/core
    - Sentry (= 9.5.1)

    What changes do you think we should make in order to solve the problem?

    Disable Sentry navigation time-to-initial-display measurement on native iOS while keeping navigation tracing itself enabled. The smallest App-side fix is to split the integration setup by platform: keep enableTimeToInitialDisplay: true for web if we still want that signal there, but export a native navigationIntegration with enableTimeToInitialDisplay: false or with the native TTID option omitted/defaulted off. setupSentry() should still include the navigation and native tracing integrations, and NavigationRoot should still register the navigation container; only the native TTID frame-tracker path should stop.

    import * as Sentry from '@sentry/react-native';
    import {breadcrumbsIntegration, browserProfilingIntegration, consoleIntegration, navigationIntegration, shouldCreateSpanForRequest} from './common';
    const tracingIntegration = Sentry.reactNativeTracingIntegration({
    shouldCreateSpanForRequest,
    });
    // The Reporting API is a browser-only feature, so there is no native integration. This stub keeps
    // the web/native export shape in parity; it is filtered out of the integrations list on native.
    const reportingObserverIntegration = undefined;
    export {navigationIntegration, tracingIntegration, browserProfilingIntegration, breadcrumbsIntegration, consoleIntegration, reportingObserverIntegration};

    import * as SentryReact from '@sentry/react';
    import {breadcrumbsIntegration, browserProfilingIntegration, consoleIntegration, navigationIntegration, shouldCreateSpanForRequest} from './common';
    /**
    * Browser tracing integration is enabled on Web to support web health measurements
    * such as INP, LCP, FCP, CLS.
    */
    const tracingIntegration = SentryReact.browserTracingIntegration({
    shouldCreateSpanForRequest,
    });
    /**
    * Reporting API integration (web only). Captures browser-emitted `crash` and `intervention`
    * reports (e.g. out-of-memory interventions) that never surface as JS exceptions, giving us an
    * early signal for browser-level crashes. See https://w3c.github.io/reporting/
    */
    const reportingObserverIntegration = SentryReact.reportingObserverIntegration({
    types: ['crash', 'intervention'],
    });
    export {navigationIntegration, tracingIntegration, browserProfilingIntegration, breadcrumbsIntegration, consoleIntegration, reportingObserverIntegration};

    const integrations = [navigationIntegration, tracingIntegration, browserProfilingIntegration, breadcrumbsIntegration, consoleIntegration, reportingObserverIntegration].filter(
    (integration): integration is NonNullable<typeof integration> => integration !== undefined,
    );
    Sentry.init({
    dsn: CONFIG.SENTRY_DSN,
    // In development, debugTransport replaces the default Sentry transport.
    // When "Send data to Sentry" toggle is ON, it forwards envelopes to Sentry via fetch.
    // When the toggle is OFF, it silently discards envelopes (returns 200 noop).
    // When "Log Sentry to console" toggle is ON, it logs envelope contents to the console.
    transport: isDevelopment() ? makeDebugTransport : undefined,
    tracesSampleRate: 1.0,
    enableAutoPerformanceTracing: true,
    enableUserInteractionTracing: true,
    integrations,

    Test coverage: Add or update a telemetry integration test that asserts the native integration does not enable TTID while the web integration keeps the intended web setup. Manually validate on iOS HybridApp by navigating between screens, confirming Sentry still receives navigation transactions/breadcrumbs, and confirming no new RNSentryTimeToDisplay / SentryFramesTracker crashes are reported.

    What alternative solutions did you explore? (Optional)

    Upgrading @sentry/react-native may also contain an upstream fix, but it is a broader JS dependency and native pod change. Disabling only native TTID is the narrower mitigation because the crash is in that measurement path, not in route tracing generally.

  5. melvin-bot commented on Jul 2, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @Krishna2323 (External)

  6. changed the title [-][Sentry: APP-7WP] HybridApp iOS EXC_BAD_ACCESS in SentryFramesTracker[/-] [+][$250] [Sentry: APP-7WP] HybridApp iOS EXC_BAD_ACCESS in SentryFramesTracker[/+] on Jul 2, 2026
  7. melvin-bot commented on Jul 2, 2026

    @melvin-bot
  8. aswin-s commented on Jul 2, 2026

    @aswin-s
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    On iOS HybridApp (v9.4.23), users experience an EXC_BAD_ACCESS crash in Sentry's SentryFramesTracker.displayLinkCallback → RNSentryTimeToDisplay putTimeToInitialDisplayForActiveSpan → NSString stringByAppendingString. 92 users and 101 events have been affected since 2026-03-18, still ongoing. Expected behavior: navigation should complete without a native crash while telemetry is being recorded.

    What is the root cause of that problem?

    navigationIntegration is configured with enableTimeToInitialDisplay: true at src/libs/telemetry/integrations/common.ts:10, and this integration is registered on native via src/setup/telemetry/setupSentry.ts:11. Under HybridApp, navigation is bridged with OldDot: the active navigation span that the native RNSentryTimeToDisplay module keeps a reference to can be ended/deallocated before the SentryFramesTracker display-link callback fires and calls putTimeToInitialDisplayForActiveSpan, which then dereferences a freed span identifier inside stringByAppendingString. The crash is only reachable when TTID tracking is enabled; disabling it on HybridApp closes the use-after-free window until the upstream @sentry/react-native 8.2.0 fix lands.

    What changes do you think we should make in order to solve the problem?

    1. src/libs/telemetry/integrations/common.ts:9-11 — Stop hard-coding enableTimeToInitialDisplay: true. Make it conditional: pass enableTimeToInitialDisplay: !CONFIG.IS_HYBRID_APP (import CONFIG from @src/CONFIG) so HybridApp iOS builds do not register the crashing native TTID hook while standalone builds keep the telemetry.
    2. src/setup/telemetry/setupSentry.ts:49 — We already tag builds with BUILD_TYPE_HYBRID_APP; confirm the tag remains so Sentry can filter/verify the crash rate drops for HybridApp after the change.
    3. Bump @sentry/react-native (currently 8.2.0 in package.json:130) to the latest 8.x that includes the upstream RNSentryTimeToDisplay null/lifetime guard for the active span (tracked in getsentry/sentry-react-native), and re-enable TTID once upgraded.
    4. Add a Sentry issue-owner note referencing [Tracking] Top Sentry crashes monthly check-in #91302 so this stays gated behind the HybridApp flag until the SDK upgrade is verified in a staged rollout.

    What alternative solutions did you explore? (Optional)

    Disable TTID globally (regressing performance visibility on standalone) or gate at the native RNSentry layer via a patch-package — both broader than needed.

  9. trasnake87 commented on Jul 2, 2026

    @trasnake87
    Contributor

    Proposal

    What is the root cause of that problem?

    The crash is a threading data-race use-after-free inside @sentry/react-native 8.2.0's iOS native module — not an App-level configuration mistake that a flag can safely paper over.

    RNSentryTimeToDisplay.m stores the active span as a static __strong global:

    static NSString *activeSpanId;
    
    + (void)setActiveSpanId:(NSString *)spanId {
        activeSpanId = spanId;   // JS thread
    }
    
    + (void)putTimeToInitialDisplayForActiveSpan:(NSNumber *)value {
        if (activeSpanId != nil) {                                          // read #1
            NSString *prefixed =
                [@"ttid-navigation-" stringByAppendingString:activeSpanId]; // read #2  ← crash
            ...
        }
    }

    setActiveSpanId: is exported as a synchronous bridge method (RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD, RNSentry.mm:953), so it executes on the JS thread. putTimeToInitialDisplayForActiveSpan: is called from the CADisplayLink frames-tracker callback (SentryFramesTracker.displayLinkCallback → RNSentryFramesTrackerListener.framesTrackerHasNewFrame → RNSentry.mm:275-276), which fires on the main run loop.

    The method reads activeSpanId twice without capturing a local strong reference. When a new navigation calls setActiveSpanId: on the JS thread between the != nil guard (read #1) and stringByAppendingString: (read #2), ARC releases the old string. If its retain count reaches zero in that window, read #2 dereferences freed memory → EXC_BAD_ACCESS in NSString stringByAppendingString — exactly the top frame in the Sentry report. ARC only guarantees thread-safe retain/release for __weak accesses and local variables; concurrent mutation of a __strong global is explicitly undefined behavior under ARC.

    Why intermittent and HybridApp-specific: the race requires the main-thread display-link callback for one navigation to be mid-flight at the same instant the JS thread promotes a new span. HybridApp's OldDot↔NewDot transitions generate far more rapid navigation span churn than standalone NewDot, dramatically widening the window — 101 events concentrated on HybridApp iOS since 2026-03-18 confirm this. A reliable reproducer: rapidly bounce between OldDot and NewDot screens so a new TTID span starts while the previous display-link frame is still emitting.

    What changes do you think we should make in order to solve the problem?

    Fix the race at its source with patch-package. The repo already patches this package (patches/sentry-react-native/@sentry+react-native+8.2.0.patch), so the workflow exists. Add to that patch:

    + (void)setActiveSpanId:(NSString *)spanId {
        @synchronized(self) {
            activeSpanId = [spanId copy];
        }
    }
    
    + (void)putTimeToInitialDisplayForActiveSpan:(NSNumber *)value {
        NSString *spanId;
        @synchronized(self) {
            spanId = activeSpanId;  // capture strong local — survives concurrent setActiveSpanId:
        }
        if (spanId != nil) {
            NSString *prefixed = [@"ttid-navigation-" stringByAppendingString:spanId];
            [self putTimeToDisplayFor:prefixed value:value];
        }
    }

    The local spanId variable retains the string for the full duration of the append; a concurrent setActiveSpanId: call can no longer deallocate it mid-read. Extend the same @synchronized(self) guard to putTimeToDisplayFor: / popTimeToDisplayFor: mutations of screenIdToRenderDuration and screenIdAge, which are equally reachable from the cross-thread emit block. Update patches/sentry-react-native/details.md with the issue link, and remove the patch when we upgrade past an SDK version that upstreams this fix.

    What alternative solutions did you explore? (Optional)

    Making enableTimeToInitialDisplay conditional on !CONFIG.IS_HYBRID_APP avoids the crash path but permanently discards TTID telemetry for HybridApp — the signal that #91302 was expressly tracking — to hide a race we can actually eliminate. Rejected: it treats the symptom while leaving the defect in place for any future path that re-enables the flag.

  10. yusufdeveloper2903 commented on Jul 2, 2026

    @yusufdeveloper2903
    Contributor

    Proposal

    What is the root cause of that problem?

    This is a native data race (use‑after‑free) inside the @sentry/react-native@8.2.0 iOS Time‑To‑Initial‑Display code, triggered by the config knob we pass to the React Navigation integration.

    We opt into native TTID measurement here:

    const navigationIntegration = Sentry.reactNavigationIntegration({
    enableTimeToInitialDisplay: true,
    });

    const navigationIntegration = Sentry.reactNavigationIntegration({
        enableTimeToInitialDisplay: true,
    });

    With enableTimeToInitialDisplay: true, on every navigation the SDK writes the active span id on the JS thread and then reads it on the main thread on the next rendered frame, with no synchronization around a shared strong static. In @sentry/react-native@8.2.0, ios/RNSentryTimeToDisplay.m:

    static NSString *activeSpanId;                                    // L14  shared __strong static
    
    + (void)setActiveSpanId:(NSString *)spanId {
        activeSpanId = spanId;                                        // L30  writer (JS thread)
    }
    
    + (void)putTimeToInitialDisplayForActiveSpan:(NSNumber *)value {
        if (activeSpanId != nil) {
            NSString *prefixedSpanId =
                [@"ttid-navigation-" stringByAppendingString:activeSpanId];  // L43  reader (main thread) 💥
            ...
        }
    }
    • The writer is exported as a synchronous native method, so setActiveSpanId: runs on the JS thread (RNSentry.mm RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(... setActiveSpanId ...)).
    • The reader runs on the main thread: CADisplayLink → SentryFramesTracker.displayLinkCallback → reportNewFrame → RNSentryFramesTrackerListener framesTrackerHasNewFrame → the emitNewFrameEvent block that calls putTimeToInitialDisplayForActiveSpan: (RNSentry.mm initFramesTracking).

    When both threads touch activeSpanId concurrently, the ARC assignment on L30 (retain new / release old) can deallocate the string that the main thread has already loaded and is about to append on L43. stringByAppendingString: then dereferences freed memory → EXC_BAD_ACCESS, which is exactly the reported stack (…putTimeToInitialDisplayForActiveSpan → NSString stringByAppendingString).

    So: enableTimeToInitialDisplay: true → SDK writes activeSpanId on JS thread while the frames tracker reads it on the main thread with no lock → old string is released mid‑append → use‑after‑free crash. This is iOS‑only because RNSentryTimeToDisplay.m/CADisplayLink is the iOS TTID implementation (Android uses a different path), matching the Sentry data: iOS HybridApp, mach EXC_BAD_ACCESS.

    The same root cause exists in a sibling flow: the static collections screenIdToRenderDuration / screenIdAge are mutated by putTimeToDisplayFor: on the main thread (L48‑L76) while popTimeToDisplayFor: mutates the same NSMutableDictionary on the JS thread (RNSentry.mm RCT_EXPORT_METHOD(popTimeToDisplayFor …)) — another unsynchronized cross‑thread access.

    What changes do you think we should make in order to solve the problem?

    Fix the root cause where it lives — serialize all access to the shared statics in the vendored SDK via patch-package. We already patch this exact package, so this extends the existing, established patch:

    https://github.com/Expensify/App/blob/a9e6aedb99c6a426f1321a28019b530bd255fe0a/patches/sentry-react-native/@sentry+react-native+8.2.0.patch

    In node_modules/@sentry/react-native/ios/RNSentryTimeToDisplay.m, guard both the write and the read with one lock and take a local strong reference before appending:

      + (void)setActiveSpanId:(NSString *)spanId {
    -     activeSpanId = spanId;
    +     @synchronized (RNSentryTimeToDisplay.class) {
    +         activeSpanId = [spanId copy];
    +     }
      }
    
      + (void)putTimeToInitialDisplayForActiveSpan:(NSNumber *)value {
    -     if (activeSpanId != nil) {
    -         NSString *prefixedSpanId = [@"ttid-navigation-" stringByAppendingString:activeSpanId];
    -         [self putTimeToDisplayFor:prefixedSpanId value:value];
    -     }
    +     NSString *spanId;
    +     @synchronized (RNSentryTimeToDisplay.class) {
    +         spanId = activeSpanId;
    +     }
    +     if (spanId != nil) {
    +         NSString *prefixedSpanId = [@"ttid-navigation-" stringByAppendingString:spanId];
    +         [self putTimeToDisplayFor:prefixedSpanId value:value];
    +     }
      }

    The local spanId keeps a strong reference alive for the duration of the append, so a concurrent setActiveSpanId: can no longer free the string out from under stringByAppendingString:.

    For the sibling race, wrap the mutations of screenIdToRenderDuration/screenIdAge inside putTimeToDisplayFor: and popTimeToDisplayFor: in the same @synchronized (RNSentryTimeToDisplay.class) block so the dictionary/array are never mutated from two threads at once. This is a minor, mechanical extension of the same fix and can be finalized in the PR phase, along with a details.md note and reporting it upstream.

    What alternative solutions did you explore? (Optional)

    • Disable the feature — set enableTimeToInitialDisplay: false in common.ts. This is a one‑line, zero‑regression change that stops the crash, but it doesn't fix the root cause and it removes the ttid-navigation telemetry we intentionally collect, so I prefer the thread‑safety patch which keeps the metric.
    • Bump @sentry/react-native past 8.2.0 if a release synchronizes this access. Correct in principle, but a minor/major SDK bump is a much larger blast radius across native/JS than the targeted patch, so it's not warranted just for this crash.
  11. 36 remaining items

  12. marufsharifi commented on Aug 5, 2026

    @marufsharifi

    @Krishna2323 @marufsharifi how is this looking in Setnry?

    @mountiny I checked the Sentry logs — the most recent crash is on 9.4.43-1, which is before our fix (shipped in 9.4.45.14). There are no crash events on that version or any newer one, so it looks resolved. The remaining events are just users still on the old pre-fix build.

  13. mountiny commented on Aug 6, 2026

    @mountiny
    ContributorAuthor

    Sounds like this is ready for payment @mallenexpensify

  14. melvin-bot commented on Aug 7, 2026

    @melvin-bot

    @mallenexpensify Whoops! This issue is 2 days overdue. Let's get this updated quick!

  15. mallenexpensify commented on Aug 8, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor: @marufsharifi due $250 via Upwork
    Contributor+: @Krishna2323 due $250 via NewDot

    @marufsharifi can you please accept the job below? Please reply here and tag me once you have.
    If you're not sent an offer in Upwork when you're assigned to an issue, please tag me. If an Upwork job exists, please submit a proposal.
    https://www.upwork.com/jobs/~022085886088117809421

  16. marufsharifi commented on Aug 8, 2026

    @marufsharifi

    @mallenexpensify, I think the price should be updated to $500, since we’ve merged two PRs (pr1, pr2)to address this issue. Thanks!

  17. mallenexpensify commented on Aug 8, 2026

    @mallenexpensify
    Contributor

    @mountiny 👀 above plz. There were two PRs, we need to figure out what the job price should be. Thx
    $250 - cuz the additional PR was part of the original job
    $375 cuz the additional PR was a followup
    $500 - separate PRs, both worth full amount.

  18. mountiny commented on Aug 9, 2026

    @mountiny
    ContributorAuthor

    Sorry I think this counts as one change, it is completely normal you need to bump the pods in oldApp as well so I think $250

  19. mallenexpensify commented on Aug 10, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor: @marufsharifi paid $250 via Upwork
    Contributor+: @Krishna2323 due $250 via NewDot

    Thx

  20. laurenreidexpensify commented on Aug 26, 2026

    @laurenreidexpensify
    Contributor

    $250 approved for @Krishna2323 New Expensify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionDailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions