Skip to content

[$250] [Sentry: APP-D1V] HybridApp iOS EXC_BAD_ACCESS in REANodesManager performOperations #96175

Closed

Description

@mountiny

Sentry

https://expensify.sentry.io/issues/APP-D1V

Impact (snapshot at filing)

  • Users (total since first seen): 127
  • Events: 127
  • Users (last 14d): 50
  • First seen: 2026-05-16
  • Last seen: now (ongoing)
  • Platform: iOS HybridApp
  • App version(s): 9.4.25 through 9.4.31
  • Affected route(s): unknown (Reanimated worklet during display link)
  • Mechanism: mach (EXC_BAD_ACCESS)

Stack trace (top frames, first-party only)

-[REANodesManager performOperations]
worklets::WorkletRuntime::runSync
AnimationFrameQueue executeQueue

Suspected cause

Reanimated native node operations crash during a worklet-driven animation frame — possible use-after-free or invalid node state when performOperations runs on the UI thread.

Reproduction

Unknown — see Sentry events linked from the Sentry issue.

Related

  • Sibling Sentry IDs (if any): none identified
  • Prior GH issues: none
Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @jakubstec

Activity

  1. added
    External
    on Jul 20, 2026
  2. self-assigned this
    on Jul 20, 2026
  3. added
    Help Wanted
    on Jul 20, 2026
  4. samranahm commented on Jul 20, 2026

    @samranahm
    Contributor

    Proposal

    What is the root cause of that problem?

    The crash is a native EXC_BAD_ACCESS inside react-native-reanimated, not inside our JS/TS code. The top frames make this clear:

    -[REANodesManager performOperations]
    worklets::WorkletRuntime::runSync
    AnimationFrameQueue executeQueue
    

    REANodesManager performOperations is where Reanimated flushes queued node/view operations on the UI thread during the iOS display link (AnimationFrameQueue). The EXC_BAD_ACCESS (mach) means the worklet is dereferencing a node or view pointer that has already been freed, i.e. a use-after-free.

    In practice this happens when a component that owns an animated node (a running useAnimatedStyle/useSharedValue-driven animation) unmounts while a frame is still queued. The view backing the node is torn down, but the pending operation in AnimationFrameQueue still tries to apply to it on the next display link tick, so performOperations touches freed memory and crashes.

    Because the signature is entirely in native Reanimated frames and reproduces across app versions 9.4.25 through 9.4.31 (no route captured), there is no single first-party TypeScript line that "causes" it. It is a native stability defect in the pinned Reanimated version combined with animations that are allowed to keep running after their host unmounts. None of the App snippets provided touch worklets directly, which confirms the fault is in the native layer rather than a specific screen.

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

    1. Bump react-native-reanimated in package.json to the latest patch that includes the performOperations / AnimationFrameQueue use-after-free hardening. This is the primary fix because the crash lives entirely in native Reanimated frames and cannot be resolved from JS alone. After bumping, regenerate Podfile.lock so the iOS HybridApp binary picks up the patched pod.

    2. As a defensive App-side guard, cancel any long-running or looping animations on unmount so no operation stays queued for a detached view. In components that start animations with withRepeat/withTiming on a useSharedValue, add a cleanup effect that calls cancelAnimation(sharedValue):

    useEffect(() => {
        return () => {
            cancelAnimation(progress);
        };
    }, [progress]);

    This stops Reanimated from enqueuing further frame operations for a node whose view is being freed, which is the exact condition that leads to the freed-pointer access in performOperations.

    1. Add a Sentry breadcrumb/tag capture around navigation transitions so future events record the affected route. Today the Sentry issue reports Affected route(s): unknown, so we cannot narrow the specific animated screen; tagging the active route on transition (near App bootstrap in App.tsx) will let us confirm the version bump resolved it or pinpoint the offending component.

    App/src/App.tsx

    Lines 72 to 76 in d24f5d7

    const StrictModeWrapper = CONFIG.USE_REACT_STRICT_MODE_IN_DEV ? React.StrictMode : ({children}: {children: React.ReactElement}) => children;
    function App() {
    useDefaultDragAndDrop();
    OnyxUpdateManager();

    What alternative solutions did you explore? (Optional)

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  5. melvin-bot commented on Jul 20, 2026

    @melvin-bot

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

  6. melvin-bot commented on Jul 20, 2026

    @melvin-bot
  7. changed the title [-][Sentry: APP-D1V] HybridApp iOS EXC_BAD_ACCESS in REANodesManager performOperations[/-] [+][$250] [Sentry: APP-D1V] HybridApp iOS EXC_BAD_ACCESS in REANodesManager performOperations[/+] on Jul 20, 2026
  8. yusufdeveloper2903 commented on Jul 20, 2026

    @yusufdeveloper2903
    Contributor

    Proposal

    What is the root cause of that problem?

    MagicCodeInput starts an infinite repeating cursor-blink animation in useEffect with no cleanup handler. When the component unmounts—especially during HybridApp transitions between OldDot and NewDot—the animation's repeating withRepeat(..., -1, false) call continues executing on the Reanimated UI thread, but the underlying animated node reference becomes invalid. When Reanimated's native REANodesManager.performOperations executes on the next display link, it operates on a deallocated or stale node pointer, triggering EXC_BAD_ACCESS.

    The bug in detail:

    const cursorOpacity = useSharedValue(1);
    useEffect(() => {
    cursorOpacity.set(withRepeat(withSequence(withDelay(500, withTiming(0, {duration: 0})), withDelay(500, withTiming(1, {duration: 0}))), -1, false));
    // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);

    const cursorOpacity = useSharedValue(1);
    
    useEffect(() => {
        cursorOpacity.set(withRepeat(withSequence(withDelay(500, withTiming(0, {duration: 0})), withDelay(500, withTiming(1, {duration: 0}))), -1, false));
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);

    The useEffect with empty dependencies fires once on mount and sets an infinite repeating animation (-1 means repeat forever). There is no cleanup function — useEffect must return a cleanup that cancels the animation before unmount, but it doesn't. The animation callback runs on the UI thread even after the component is destroyed, and when React Navigation unmounts or transitions (especially during HybridApp navigation), the Reanimated node is deallocated. The next scheduled animation frame tries to update a dead node.

    Why the sibling case works:

    LoadingBar.tsx has the exact same pattern but with proper cleanup:

    } else {
    opacity.set(
    withTiming(0, {duration: CONST.ANIMATED_PROGRESS_BAR_OPACITY_DURATION}, () => {
    cancelAnimation(left);
    cancelAnimation(width);
    }),
    );

    } else {
        opacity.set(
            withTiming(0, {duration: CONST.ANIMATED_PROGRESS_BAR_OPACITY_DURATION}, () => {
                cancelAnimation(left);
                cancelAnimation(width);
            }),
        );
    }

    When shouldShow becomes false, it explicitly calls cancelAnimation(left) and cancelAnimation(width) before the component unmounts. PulsingView.tsx uses useAnimatedReaction with explicit cancelAnimation calls as well:

    function stopPulse(opacity: SharedValue<number>) {
    'worklet';
    cancelAnimation(opacity);
    opacity.set(withTiming(1, {duration: RECOVERY_DURATION, easing: EASING_OUT}));
    }

    function stopPulse(opacity: SharedValue<number>) {
        'worklet';
    
        cancelAnimation(opacity);
        opacity.set(withTiming(1, {duration: RECOVERY_DURATION, easing: EASING_OUT}));
    }

    Both components explicitly stop animations before destruction. MagicCodeInput does not.

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

    Add a cleanup function to the useEffect that cancels the cursor animation on unmount:

    const cursorOpacity = useSharedValue(1);
    
    useEffect(() => {
        cursorOpacity.set(withRepeat(withSequence(withDelay(500, withTiming(0, {duration: 0})), withDelay(500, withTiming(1, {duration: 0}))), -1, false));
        
        return () => {
            cancelAnimation(cursorOpacity);
        };
    }, []);

    Why this is safe:

    • useSharedValue is created inside the component, so the cleanup function always runs before the value is garbage-collected.
    • cancelAnimation() is idempotent — calling it on an already-stopped animation is safe.
    • The animation is local to MagicCodeInput and has no side effects outside the component, so canceling it on unmount has no impact on other state.
    • This pattern is already proven in LoadingBar and PulsingView — we are simply applying the same guard that works elsewhere.

    We can also apply the same fix to any other infinite animation that uses withRepeat(..., -1) without explicit cleanup. A grep for withRepeat.*-1 across components would find similar patterns.

    What alternative solutions did you explore? (Optional)

    • Move the animation to a context or module-level instance: Wrong — the animation is tied to the individual component's lifecycle and its visual state. Decoupling it would make it harder to reason about and introduce race conditions during navigation.
    • Use useAnimatedReaction instead of useEffect: This could work, but useAnimatedReaction is for reactive dependencies on shared values, not one-time setup. A simple cleanup in useEffect is clearer and matches the pattern already in the codebase.
  9. KJ21-ENG commented on Jul 20, 2026

    @KJ21-ENG
    Contributor

    Proposal

    What is the root cause of that problem?

    This is a native Reanimated race, not a route-specific JavaScript failure. During an iOS display-link tick, Worklets flushes the animation-frame queue on the UI runtime and Reanimated calls REANodesManager.performOperations. That operation can overlap a React Native surface commit/teardown and dereference stale native update state, producing the reported EXC_BAD_ACCESS.

    The issue's three first-party frames (REANodesManager.performOperations → WorkletRuntime::runSync → AnimationFrameQueue.executeQueue) match upstream Reanimated issue #9293's symbolicated rAF crash path exactly. Upstream fixed that race through registry locking and performOperations/render-request atomicity changes in PRs #9323 and #9308.

    software-mansion/react-native-reanimated#9293

    software-mansion/react-native-reanimated#9323

    software-mansion/react-native-reanimated#9308

    The regression timing also aligns: App merged the Reanimated 4.2.3 and Worklets 0.8.1 upgrades in PRs #90086 and #90088 on May 11–12, and Sentry first saw this crash on May 16. The current App dependency manifest has since moved to 4.3.1/0.8.3, but Reanimated 4.3.1 cherry-picked #9323 and omitted #9308, and APP-D1V remains active through App 9.4.31.

    #90086

    #90088

    App/package.json

    Lines 180 to 218 in 6a1f1a3

    "react-native": "0.85.3",
    "react-native-advanced-input-mask": "1.4.6",
    "react-native-app-logs": "0.3.1",
    "react-native-blob-util": "0.24.9",
    "react-native-collapsible": "^1.6.2",
    "react-native-config": "1.5.3",
    "react-native-device-info": "10.3.1",
    "react-native-draggable-flatlist": "^4.0.3",
    "react-native-fs": "^2.20.0",
    "react-native-gesture-handler": "2.32.0",
    "react-native-google-places-autocomplete": "2.5.6",
    "react-native-haptic-feedback": "^2.3.3",
    "react-native-image-picker": "^7.1.2",
    "react-native-image-size": "git+https://github.com/Expensify/react-native-image-size#8a1c3b7359977462cdd4e63b09ea45afbd3d77c7",
    "react-native-key-command": "1.0.14",
    "react-native-keyboard-controller": "1.21.0-beta.1",
    "react-native-localize": "^3.5.4",
    "react-native-nitro-modules": "0.35.0",
    "react-native-nitro-sqlite": "9.6.0",
    "react-native-onyx": "3.0.88",
    "react-native-pager-view": "8.0.0",
    "react-native-pdf": "7.0.2",
    "react-native-permissions": "^5.4.0",
    "react-native-picker-select": "github:Expensify/react-native-picker-select#69d750a89aaba48392fb8b6f92a3d79f53b99c41",
    "react-native-plaid-link-sdk": "12.5.3",
    "react-native-qrcode-svg": "6.3.21",
    "react-native-reanimated": "4.3.1",
    "react-native-render-html": "6.3.1",
    "react-native-safe-area-context": "5.6.2",
    "react-native-screens": "4.25.0",
    "react-native-share": "11.0.2",
    "react-native-svg": "15.15.5",
    "react-native-tab-view": "^4.3.0",
    "react-native-url-polyfill": "^2.0.0",
    "react-native-view-shot": "5.1.0",
    "react-native-vision-camera": "^4.7.2",
    "react-native-web": "0.21.2",
    "react-native-webview": "13.16.0",
    "react-native-worklets": "0.8.3",

    HybridApp production builds use the Mobile-Expensify Xcode workspace and its Podfile.lock, rather than the standalone App iOS lockfile. The supplied checkout does not contain that submodule, so the implementation must first confirm the exact RNReanimated/Worklets pod versions and dSYM symbols in an affected HybridApp build. This changes which lockfile must be updated, but not the producer identified by the matching native stack.

    App/fastlane/Fastfile

    Lines 314 to 370 in 6a1f1a3

    platform :ios do
    desc "Build an iOS HybridApp production build"
    lane :build_hybrid do
    ENV["ENVFILE"]="Mobile-Expensify/.env.production.hybridapp.ios"
    setupIOSSigningCertificate()
    install_provisioning_profile(
    path: "./" + ENV["APPLE_STORE_PROVISIONING_PROFILE_FILE"]
    )
    install_provisioning_profile(
    path: "./" + ENV["APPLE_SHARE_PROVISIONING_PROFILE_FILE"]
    )
    install_provisioning_profile(
    path: "./" + ENV["APPLE_NOTIFICATION_PROVISIONING_PROFILE_FILE"]
    )
    install_provisioning_profile(
    path: "./" + ENV["APPLE_LIVE_ACTIVITY_PROVISIONING_PROFILE_FILE"]
    )
    update_code_signing_settings(
    path: "Mobile-Expensify/iOS/Expensify.xcodeproj",
    profile_name: ENV["APPLE_STORE_PROVISIONING_PROFILE_NAME"],
    targets: "Expensify",
    bundle_identifier: ENV["APPLE_ID"],
    build_configurations: "Release"
    )
    update_code_signing_settings(
    path: "Mobile-Expensify/iOS/Expensify.xcodeproj",
    profile_name: ENV["APPLE_SHARE_PROVISIONING_PROFILE_NAME"],
    targets: "SmartScanExtension",
    bundle_identifier: ENV["APPLE_ID"] + ".SmartScanExtension",
    build_configurations: "Release"
    )
    update_code_signing_settings(
    path: "Mobile-Expensify/iOS/Expensify.xcodeproj",
    profile_name: ENV["APPLE_NOTIFICATION_PROVISIONING_PROFILE_NAME"],
    targets: "NotificationServiceExtension",
    bundle_identifier: ENV["APPLE_ID"] + ".NotificationServiceExtension",
    build_configurations: "Release"
    )
    update_code_signing_settings(
    path: "Mobile-Expensify/iOS/Expensify.xcodeproj",
    profile_name: ENV["APPLE_LIVE_ACTIVITY_PROVISIONING_PROFILE_NAME"],
    targets: "LiveActivityExtension",
    bundle_identifier: ENV["APPLE_ID"] + ".LiveActivityExtension",
    build_configurations: "Release"
    )
    build_app(
    workspace: "Mobile-Expensify/iOS/Expensify.xcworkspace",

    # See if we're in the HybridApp repo
    IS_HYBRID_APP_REPO=$(scripts/is-hybrid-app.sh)
    # See if we should force standalone NewDot build
    NEW_DOT_FLAG="${STANDALONE_NEW_DOT:-false}"
    if [[ "$IS_HYBRID_APP_REPO" == "true" && "$NEW_DOT_FLAG" == "false" ]]; then
    echo -e "${BLUE}Executing npm run pod-install for HybridApp...${NC}"
    # Navigate to the OldDot repository, and run bundle install and pod install
    cd Mobile-Expensify/ios
    bundle install
    RCT_USE_RN_DEP=0 RCT_USE_PREBUILT_RNCORE=0 bundle exec pod install
    exit 0

    App/.gitmodules

    Lines 1 to 3 in 6a1f1a3

    [submodule "Mobile-Expensify"]
    path = Mobile-Expensify
    url = git@github.com:Expensify/Mobile-Expensify.git

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

    After confirming the affected HybridApp resolves the App Reanimated pod, upgrade react-native-reanimated to 4.4.0 and, because 4.4.0 requires Worklets 0.9.x, upgrade react-native-worklets to 0.9.1 in the same change. Reanimated 4.4.0 contains both upstream race fixes (#9323 and the missing #9308), along with the rAF/event separation and shared ShadowNodeFamily lifetime changes that harden this same native update path. Regenerate package-lock.json, the standalone native lockfiles, and Mobile-Expensify's HybridApp Podfile.lock so the shipped iOS binary actually links the fixed pair.

    https://github.com/software-mansion/react-native-reanimated/releases/tag/4.4.0

    https://github.com/software-mansion/react-native-reanimated/releases/tag/worklets-0.9.1

    Reconcile the App and Mobile-Expensify patch sets as part of the bump; HybridApp installation applies patches from both directories to the installed modules.

    # See if we're in the HybridApp repo
    IS_HYBRID_APP_REPO=$(scripts/is-hybrid-app.sh)
    readonly IS_HYBRID_APP_REPO
    readonly NEW_DOT_FLAG="${STANDALONE_NEW_DOT:-false}"
    # Wrapper to run patch-package.
    function patchPackage() {
    TEMP_PATCH_DIR=$(mktemp --directory ./tmp-patches-XXX)
    trap 'rm -rf "$TEMP_PATCH_DIR"' RETURN
    find ./patches -type f -name '*.patch' -exec cp {} "$TEMP_PATCH_DIR" \;
    if [[ "$IS_HYBRID_APP_REPO" == "true" && "$NEW_DOT_FLAG" == "false" ]]; then
    find ./Mobile-Expensify/patches -type f -name '*.patch' -exec cp {} "$TEMP_PATCH_DIR" \;
    fi
    if ! npx patch-package --patch-dir "$TEMP_PATCH_DIR" --error-on-fail --color=always; then

    Keep and refresh the App Reanimated stoi exception patch for 4.4.0 because upstream still catches only invalid_argument and out_of_range. Remove the Worklets 0.8.3 SerializableRemoteFunction patch after verifying 0.9.1, because Worklets 0.9.1 replaces that remote-function memory model with runtime-aware cleanup and an RN-runtime registry, covering the patch's unsafe cross-thread JSI-lifetime concern upstream.

    # `react-native-reanimated` patches
    ### [react-native-reanimated+4.3.1+001+catch-all-exceptions-on-stoi.patch](react-native-reanimated+4.3.1+001+catch-all-exceptions-on-stoi.patch)
    - Reason: Reanimated wasn't able to catch an exception here, so the catch clause was broadened.
    - Upstream PR/issue: 🛑
    - E/App issue: 🛑
    - PR Introducing Patch: [Upgrade to React Native 0.76](https://github.com/Expensify/App/pull/51475)

    # `react-native-worklets` patches
    ### [react-native-worklets+0.8.3+001+fix-app-crash-SerializableRemoteFunction.patch](react-native-worklets+0.8.3+001+fix-app-crash-SerializableRemoteFunction.patch)
    - Reason: Fixes SIGSEGV crash in `SerializableRemoteFunction` destructor caused by a data race on `globalMarkdownWorkletRuntime`. The fix replaces the stored `jsi::Value` function reference with an ID-based lookup via a `__remoteFunctionCache` map, avoiding the unsafe cross-thread `~jsi::Value()` call during runtime teardown.
    - Upstream PR/issue: N/A (patch authored by the `react-native-worklets` maintainer in https://github.com/Expensify/react-native-live-markdown/pull/752#issuecomment-3953415007)
    - E/App issue: https://github.com/Expensify/App/issues/82146
    - PR Introducing Patch: [#83792](https://github.com/Expensify/App/pull/83792)

    Test coverage:

    • Add a native iOS HybridApp regression/stress test that enqueues animation-frame work, then rapidly unmounts/remounts the React surface during active transitions and verifies the operation completes or is discarded without a crash.
    • Exercise repeated NewDot/OldDot transitions, background/foreground cycles, and animation-heavy layout/gesture/modal/list/live-markdown flows under Address Sanitizer; repeat app/runtime teardown to validate removal of the old Worklets patch.
    • Produce a release-mode HybridApp build and verify its dSYM and Mobile-Expensify Podfile.lock resolve Reanimated 4.4.0 and Worklets 0.9.1; verify the standalone iOS/Android lockfiles too, then monitor APP-D1V after staged rollout. Because this is a native timing race without a deterministic route, release stress coverage and the production Sentry check are required in addition to the native harness.

    What alternative solutions did you explore? (Optional)

    Backporting only #9308 onto the HybridApp's resolved Reanimated version would target the missing change, but the compatible stable 4.4.0/0.9.1 pair already contains it plus the adjacent lifetime and scheduling fixes, avoiding another long-lived native patch. Rolling back to 4.2.1 is also weaker because events continued after the App manifest moved forward and it would reintroduce fixes from later releases. Disabling individual animations, or adding speculative Mobile-Expensify teardown guards without first tying the symbol to shell-owned code, would suppress selected consumers instead of fixing the verified Reanimated producer.

  10. 13 remaining items

  11. mountiny commented on Aug 6, 2026

    @mountiny
    ContributorAuthor

    Lets wait couple more days but looks promising

  12. melvin-bot commented on Aug 10, 2026

    @melvin-bot

    @jakubstec Eep! 4 days overdue now. Issues have feelings too...

  13. jakubstec commented on Aug 11, 2026

    @jakubstec
    Member

    still zero occurences!

  14. melvin-bot commented on Aug 14, 2026

    @melvin-bot

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

  15. jakubstec commented on Aug 17, 2026

    @jakubstec
    Member

    @mountiny 0 crashes in the last 7 days, and still none of post 9.4.45-14 release

  16. mountiny commented on Aug 17, 2026

    @mountiny
    ContributorAuthor

    Seems like this is fixed!

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

Metadata

Metadata

Labels

DailyExternal

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions