react-native-reanimated icon indicating copy to clipboard operation
react-native-reanimated copied to clipboard

ANR caused in performOperations

Open heroic opened this issue 3 years ago • 13 comments

Description

We are seeing multiple ANRs with reanimated at the top of the stacktrace. These are not showing in bugsnag either, only on Play Store which is now penalising our app.

Expected behavior

No ANR

Actual behavior & steps to reproduce

"main" prio=5 tid=1 Waiting
  at sun.misc.Unsafe.park (Native method)
  at java.util.concurrent.locks.LockSupport.park (LockSupport.java:190)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt (AbstractQueuedSynchronizer.java:868)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly (AbstractQueuedSynchronizer.java:1023)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly (AbstractQueuedSynchronizer.java:1334)
  at java.util.concurrent.Semaphore.acquire (Semaphore.java:318)
  at com.swmansion.reanimated.NodesManager.performOperations (NodesManager.java:230)
  at com.swmansion.reanimated.NodesManager.onAnimationFrame (NodesManager.java:259)
  at com.swmansion.reanimated.NodesManager.access$000 (NodesManager.java:65)
  at com.swmansion.reanimated.NodesManager$1.doFrameGuarded (NodesManager.java:153)
  at com.facebook.react.uimanager.GuardedFrameCallback.doFrame (GuardedFrameCallback.java:29)
  at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame (ReactChoreographer.java:175)
  at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame (ChoreographerCompat.java:85)
  at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1063)
  at android.view.Choreographer.doCallbacks (Choreographer.java:889)
  at android.view.Choreographer.doFrame (Choreographer.java:812)
  at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1050)
  at android.os.Handler.handleCallback (Handler.java:883)
  at android.os.Handler.dispatchMessage (Handler.java:100)
  at android.os.Looper.loop (Looper.java:237)
  at android.app.ActivityThread.main (ActivityThread.java:7830)
  at java.lang.reflect.Method.invoke (Native method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:492)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1040)

Snack or minimal code example

None available

Package versions

  • React Native: 0.63.4
  • React Native Reanimated: 2.2.0
  • NodeJS: 16.0.0
  • Xcode:
  • Java & Gradle: openjdk 11.0.8 gradle 6.5

Affected platforms

  • [x] Android
  • [ ] iOS
  • [ ] Web

heroic avatar Aug 04 '21 03:08 heroic

Issue validator

The issue is valid!

github-actions[bot] avatar Aug 04 '21 03:08 github-actions[bot]

I am experiencing exactly the same issue since upgrading to 2.3 in production.

Input dispatching timed out (9fff00a [My app Activity] (server) is not responding. Waited 10002ms for FocusEvent(hasFocus=false))

"main" prio=5 tid=1 Waiting

 at sun.misc.Unsafe.park (Native method)
  at java.util.concurrent.locks.LockSupport.park (LockSupport.java:190)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt (AbstractQueuedSynchronizer.java:868)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly (AbstractQueuedSynchronizer.java:1023)
  at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly (AbstractQueuedSynchronizer.java:1334)
  at java.util.concurrent.Semaphore.acquire (Semaphore.java:318)
  at com.swmansion.reanimated.NodesManager.performOperations (NodesManager.java:249)
  at com.swmansion.reanimated.NodesManager.onAnimationFrame (NodesManager.java:278)
  at com.swmansion.reanimated.NodesManager.access$000 (NodesManager.java:63)
  at com.swmansion.reanimated.NodesManager$1.doFrameGuarded (NodesManager.java:168)
  at com.facebook.react.uimanager.GuardedFrameCallback.doFrame (GuardedFrameCallback.java:29)
  at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame (ReactChoreographer.java:175)
  at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame (ChoreographerCompat.java:85)
  at android.view.Choreographer$CallbackRecord.run (Choreographer.java:970)
  at android.view.Choreographer.doCallbacks (Choreographer.java:796)
  at android.view.Choreographer.doFrame (Choreographer.java:727)
  at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:957)
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:250)
  at android.app.ActivityThread.main (ActivityThread.java:7868)
  at java.lang.reflect.Method.invoke (Native method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:592)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:958)

image image

beetlebum avatar Dec 09 '21 15:12 beetlebum

Hey @heroic

Did you find any solution for it? We started facing a similar issue when we moved from APK to App bundle.

Thanks.

joy-betterhalf avatar Jan 10 '22 19:01 joy-betterhalf

Hi all, thanks for reporting. The ANR is likely cause by a deadlock due to the code we use for making synchronizing UI updates. However, w/o more details it is very little we can do about it. It'd be important for us to get some more information about what kind of animations run when this occurs, or get traces from other threads if available. Any kind of additional detail that you may share may be helpful in getting to the bottom of this issue.

kmagiera avatar Jan 28 '22 09:01 kmagiera

From what I can tell the only animations that are happening are the React Navigation screen changes. We're seeing this when going from one Screen to a Screen containing Tabs, and also when going from one simple Screen to another Screen.

Here's a pastebin from one of the crash logs: https://pastebin.com/pxBRCn63

heroic avatar Jan 28 '22 14:01 heroic

@heroic

Can you please confirm your react navigation version?

We are also seeing similar behavior at the same place where we are using Stack navigation > Tab navigation

joy-betterhalf avatar Jan 28 '22 21:01 joy-betterhalf

@joy-betterhalf RN v5

heroic avatar Jan 29 '22 06:01 heroic

@kmagiera In our case, we have tried removing every place where we directly use react-native-reanimated for animation and kept the library as a dependency for other modules such as https://gorhom.github.io/react-native-bottom-sheet/ still we are getting many ANRs with the same error everyone facing here and we are not sure what causes the ANR and that's why I asked @heroic on React navigation version since I thought it's old and could be causing this problem. We were using V4 which now migrated to V5 but still, we are facing the same issue.

joy-betterhalf avatar Feb 03 '22 19:02 joy-betterhalf

Same issue here

geroale avatar Mar 10 '22 18:03 geroale

We have the same issue.

marf avatar Mar 10 '22 18:03 marf

can we merge this ? still facing this issue..

ohheyitskartik avatar Sep 07 '22 02:09 ohheyitskartik

Yes, please merge the PR #3440 in the master and release an update to hopefully fix this issue. Thanks!

marf avatar Sep 07 '22 06:09 marf

Facing same issue on android multiple devices: React-native : 0.66.4 react-native-reanimated : 2.9.1 (^2.2 on package.json)

"dependencies": { "@ptomasroos/react-native-multi-slider": "^2.2.2", "@react-native-async-storage/async-storage": "^1.15.4", "@react-native-community/art": "https://github.com/react-native-art/art.git", "@react-native-community/blur": "^3.6.0", "@react-native-community/masked-view": "^0.1.10", "@react-native-community/slider": "^3.0.3", "@react-native-firebase/analytics": "^11.5.0", "@react-native-firebase/app": "^11.5.0", "@react-native-firebase/crashlytics": "^11.5.0", "@react-native-firebase/messaging": "^11.5.0", "@react-native-firebase/perf": "^11.5.0", "@react-navigation/bottom-tabs": "^5.11.9", "@react-navigation/native": "^5.9.4", "@react-navigation/stack": "^5.14.4", "@reduxjs/toolkit": "^1.5.1", "@sentry/react-native": "^3.1.1", "@shopify/restyle": "^1.4.0", "@snowplow/react-native-tracker": "^1.2.1", "axios": "^0.21.1", "babel-plugin-module-resolver": "^4.1.0", "babel-plugin-transform-remove-console": "^6.9.4", "clevertap-react-native": "^0.8.1", "launchdarkly-react-native-client-sdk": "^5.1.0", "lodash": "^4.17.21", "lottie-ios": "3.4.0", "lottie-react-native": "^5.1.3", "moment": "^2.29.1", "query-string": "^7.0.0", "react": "17.0.2", "react-native": "0.66.3", "react-native-branch": "^5.5.0", "react-native-code-push": "^7.0.4", "react-native-dash": "^0.0.11", "react-native-dropdown-picker": "5.0", "react-native-fast-image": "^8.3.4", "react-native-fbsdk-next": "^7.0.1", "react-native-flipper": "^0.91.2", "react-native-geocoding": "^0.5.0", "react-native-geolocation-service": "5.2.0", "react-native-gesture-handler": "^2.4.0", "react-native-image-pan-zoom": "^2.1.12", "react-native-in-app-review": "^3.2.3", "react-native-linear-gradient": "^2.5.6", "react-native-modal": "^13.0.1", "react-native-modal-dropdown": "^1.0.0", "react-native-neomorph-shadows": "^1.1.2", "react-native-otp-verify": "^1.0.4", "react-native-pager-view": "^5.1.9", "react-native-progress": "^5.0.0", "react-native-radial-gradient": "^1.0.9", "react-native-reanimated": "2.6.0", "react-native-render-html": "^6.3.4", "react-native-safe-area-context": "^3.2.0", "react-native-screens": "^3.1.1", "react-native-shimmer-placeholder": "^2.0.7", "react-native-simple-toast": "^1.1.3", "react-native-size-matters": "^0.4.0", "react-native-smooth-picker": "^1.1.5", "react-native-splash-screen": "^3.2.0", "react-native-svg": "^12.1.1", "react-native-svg-transformer": "^0.14.3", "react-native-tab-view": "^3.0.1", "react-native-tracking-transparency": "^0.1.1", "react-native-ultimate-config": "^3.3.4", "react-native-version-info": "^1.1.0", "react-native-video": "^5.2.0", "react-native-walkthrough-tooltip": "^1.3.0", "react-native-webview": "^11.4.0", "react-native-wheel-scrollview-picker": "^2.0.0", "react-redux": "^7.2.3", "redux-flipper": "^1.4.2", "redux-logger": "^3.0.6", "redux-persist": "^6.0.0", "yup": "^0.32.9" },

viv3kk avatar Sep 22 '22 12:09 viv3kk

Did anyone tried this change https://github.com/software-mansion/react-native-reanimated/pull/3440 in prod?

androideveloper avatar Oct 13 '22 10:10 androideveloper

We're seeing this as well and it started when we integrated react-native-reanimated-carousel. If we show a carousel right away after app launch, the app hangs and never recovers. I don't know if that helps you but we had to disable our tutorial carousel as a result and are still seeing ANRs as a result. The crash happens before there is any interaction with the carousel.

HilSny avatar Nov 02 '22 19:11 HilSny

We don't use react-native-reanimated-carousel but this ANR started increasing for us once we added more animations on the same screen using reanimated.

Quick update from our side. We patched this fix (using rn-patch) and shipped on prod https://github.com/software-mansion/react-native-reanimated/pull/3440 and number of ANRs decreased significantly! 🚀 In order to patch it properly, we needed to force rebuild reanimated from source by passing reanimated = [ buildFromSource: true ] to gradle config.

There's a small issue with this approach, but overall the app is more stable

androideveloper avatar Nov 03 '22 10:11 androideveloper

Same ANRs in production here! This is by far the most common ANR cause in our apps at the moment (+60%) Any workarounds while the bug is fixed?

gollobo avatar Jan 17 '23 11:01 gollobo

See my comment above

androideveloper avatar Jan 19 '23 09:01 androideveloper

Following. We are also seeing significant crashes for iOS that appear related to this, thousands daily.

jedashford avatar Feb 09 '23 02:02 jedashford

@androideveloper is your fix working well so far in production app ? any issues you see like animation is starting with delay ? we are also seeing same ANRs on play console.

pavangoyal42 avatar Feb 15 '23 17:02 pavangoyal42

No major issues so far 👍

androideveloper avatar Feb 21 '23 17:02 androideveloper

Thanks for the help @androideveloper, we had added the patch https://github.com/software-mansion/react-native-reanimated/pull/3440 in our app. This helps us to fix the ANR issue on the app 👍

But using the above fix we facing an increase in user crashes, below is the crash log for the same.

Fatal Exception: com.facebook.jni.CppException: bad_weak_ptr
       at com.swmansion.reanimated.Scheduler.triggerUI(Scheduler.java)
       at com.swmansion.reanimated.Scheduler$1.run(Scheduler.java:24)
       at com.swmansion.reanimated.Scheduler$2.runGuarded(Scheduler.java:43)
       at com.facebook.react.bridge.GuardedRunnable.run(GuardedRunnable.java:31)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:257)
       at android.app.ActivityThread.main(ActivityThread.java:8218)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:626)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1016)

We are using react-native version 0.69.4 and react-native-reanimated version 2.12.0.

prince-housing avatar Mar 10 '23 10:03 prince-housing

@androideveloper we have also applied the patch. no anr or issue so far. @prince-housing we were also facing this crash. I can confirm react-native-reanimated 3.0.0 solved the issue for us. no instances seen after 3.0.0.

pavangoyal42 avatar Mar 10 '23 10:03 pavangoyal42

@pavangoyal42 did you also use the patch with react-native-reanimated 3.0.0?

prince-housing avatar Mar 10 '23 10:03 prince-housing

@prince-housing yes I have used patch with 3.0.0. this solved the crash and ANR. so side effects as of now.

pavangoyal42 avatar Mar 10 '23 12:03 pavangoyal42

Fixed with https://github.com/software-mansion/react-native-reanimated/pull/4239, the fix is available since 3.+ versions

piaskowyk avatar May 23 '23 10:05 piaskowyk