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
    ExternalAdded to denote the issue can be worked on by a contributor
    on Jul 20, 2026
  2. self-assigned this
    on Jul 20, 2026
  3. added
    Help WantedApply this label when an issue is open to proposals by contributors
    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. 14 remaining items

  10. mountiny commented on Aug 6, 2026

    @mountiny
    ContributorAuthor

    Lets wait couple more days but looks promising

  11. melvin-bot commented on Aug 10, 2026

    @melvin-bot

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

  12. jakubstec commented on Aug 11, 2026

    @jakubstec
    Member

    still zero occurences!

  13. melvin-bot commented on Aug 14, 2026

    @melvin-bot

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

  14. 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

  15. 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

DailyKSv2ExternalAdded 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