software-mansion / react-native-reanimated

React Native's Animated library reimplemented
https://docs.swmansion.com/react-native-reanimated/
MIT License
9.11k stars 1.32k forks source link

ConcurrentModificationException crash on Android #5822

Closed Vepsur closed 7 months ago

Vepsur commented 8 months ago

Description

I got a crash error in my Sentry in the production version of the app on Android

Sentry report:

ConcurrentModificationException java.util.HashMap$HashIterator in nextNode mechanism: UncaughtExceptionHandler

Stack trace:

java.util.HashMap$HashIterator in nextNode at line 1574
java.util.HashMap$ValueIterator in next at line 1602
com.swmansion.reanimated.keyboard.KeyboardAnimationManager in notifyAboutKeyboardChange at line 44
com.swmansion.reanimated.keyboard.KeyboardAnimationManager$$ExternalSyntheticLambda0 in call at line 2
com.swmansion.reanimated.keyboard.WindowsInsetsManager in onApplyWindowInsetsListener at line 63
com.swmansion.reanimated.keyboard.WindowsInsetsManager in $r8$lambda$Gx1x4Lxu9gvvZb85XEKpmqU242U
com.swmansion.reanimated.keyboard.WindowsInsetsManager$$ExternalSyntheticLambda2 in onApplyWindowInsets at line 2
androidx.core.view.ViewCompat$Api21Impl$1 in onApplyWindowInsets at line 4858
android.view.View in dispatchApplyWindowInsets at line 12341
android.view.ViewGroup in dispatchApplyWindowInsets at line 7868
android.view.ViewRootImpl in dispatchApplyInsets at line 3683
android.view.ViewRootImpl in performTraversals at line 3963
android.view.ViewRootImpl in doTraversal at line 3248
android.view.ViewRootImpl$TraversalRunnable in run at line 11206
android.view.Choreographer$CallbackRecord in run at line 1650
android.view.Choreographer$CallbackRecord in run at line 1659
android.view.Choreographer in doCallbacks at line 1129
android.view.Choreographer in doFrame at line 1055
android.view.Choreographer$FrameDisplayEventReceiver in run at line 1622
android.os.Handler in handleCallback at line 958
android.os.Handler in dispatchMessage at line 99
android.os.Looper in loopOnce at line 230
android.os.Looper in loop at line 319
android.app.ActivityThread in main at line 8893
java.lang.reflect.Method in invoke
com.android.internal.os.RuntimeInit$MethodAndArgsCaller in run at line 608
com.android.internal.os.ZygoteInit in main at line 1103

I faced this bug in the dev environment. I solved it in debug mode on my Android via the created async hook, which waits while the keyboard closes and only then navigates to another screen. But I got the error in my Sentry after releasing a new version with fixes, so I missed something.

P.S. I also suggest that can be related to react-native-keyboard-controller or react-native-screens enableFreeze(true) and will continue my investigation

22-mar updates:

5-apr updates:

Steps to reproduce

  1. Tap on the Navigate to profile button

  2. Immediately after navigation, tap on text input

  3. The app should crash most of the time

  4. Tap on the Navigate to profile button

  5. After navigation, tap on text input

  6. While the keyboard is open, try scrolling FlatList

  7. The app should crash often enough

Snack or a link to a repository

reanimated-android-crash-example

Reanimated version

3.8.0

React Native version

0.72.6

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native

Architecture

Paper (Old Architecture)

Build type

Release app & production bundle

Device

Real device

Device model

No response

Acknowledgements

Yes

tomekzaw commented 8 months ago

Hi @Vepsur, thanks for reporting this issue. It looks like something related to useAnimatedKeyboard which we have recently refactored. Assigning our keyboard expert @piaskowyk.

Vepsur commented 8 months ago

Here are a few updates about the behavior of the crash:

And I will try to create a separate reproduction repository for that issue

solitarysp commented 8 months ago

I also received the same error.

image
Vepsur commented 8 months ago

Here are a few updates about the behavior of the crash:

Vepsur commented 8 months ago

android-keyboard-renimated-crash (1) android-keyboard-renimated-crash (2)

tomekzaw commented 8 months ago

cc @maciekstosio

maciekstosio commented 7 months ago

Hi, I posted PR (#5918) that should fix that. Let me know if it helps.

Vepsur commented 7 months ago

I checked it in the repo repository and in our project, it seems like it resolved this issue. Thanks!