software-mansion / react-native-reanimated

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

[iOS] App freeze and crash in production build randomly #2938

Closed GuoXiaoyang closed 9 months ago

GuoXiaoyang commented 2 years ago

Description

Expected behavior

Do not freeze and crash.

Actual behavior & steps to reproduce

It happens more after staying background for a long time and then comes back to the app by slide gesture. It freezes and then crashes after seconds.

Crash log

Version:             2.2.0 (27)
AppStoreTools:       13C90b
AppVariant:          1:iPhone11,8:15
Beta:                YES
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           com.xx.xx.xx [2557]

Date/Time:           2022-02-04 16:26:54.0104 +0800
Launch Time:         2022-02-04 15:43:01.8122 +0800
OS Version:          iPhone OS 15.2.1 (19C63)
Release Type:        User
Baseband Version:    4.02.02
Report Version:      104

Exception Type:  EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Termination Reason: FRONTBOARD 2343432205 
<RBSTerminateContext| domain:10 code:0x8BADF00D explanation:scene-update watchdog transgression: application<com.moement.moego.business>:28852 exhausted real (wall clock) time allowance of 10.00 seconds
ProcessVisibility: Foreground
ProcessState: Running
WatchdogEvent: scene-update
WatchdogVisibility: Background
WatchdogCPUStatistics: (
"Elapsed total CPU time (seconds): 19.480 (user 19.480, system 0.000), 30% CPU",
"Elapsed application CPU time (seconds): 0.107, 0% CPU"
) reportType:CrashLog maxTerminationResistance:Interactive>

Triggered by Thread:  0

Kernel Triage:
VM - Compressor failed a blocking pager_get
VM - Compressor failed a blocking pager_get
VM - Compressor failed a blocking pager_get
VM - Compressor failed a blocking pager_get
VM - Compressor failed a blocking pager_get

Thread 0 name:
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x00000001b915a66c __psynch_mutexwait + 8
1   libsystem_pthread.dylib         0x00000001f25fc3cc _pthread_mutex_firstfit_lock_wait + 84 (pthread_mutex.c:1414)
2   libsystem_pthread.dylib         0x00000001f260350c _pthread_mutex_firstfit_lock_slow + 240 (pthread_mutex.c:1490)
3   business                        0x0000000102952a94 -[RCTEventDispatcher sendEvent:] + 84 (RCTEventDispatcher.mm:124)
4   business                        0x0000000102874c00 -[REAEventDispatcher sendEvent:] + 164 (REAEventDispatcher.m:11)
5   business                        0x00000001028dd58c __createEventSetter_block_invoke_2 + 260 (RCTComponentData.m:122)
6   business                        0x000000010297b028 -[RCTImageView reloadImage] + 224 (RCTImageView.mm:308)
7   business                        0x000000010297c34c -[RCTImageView didMoveToWindow] + 136 (RCTImageView.mm:0)
8   UIKitCore                       0x00000001842ece78 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 2228 (UIView.m:15964)
9   UIKitCore                       0x00000001842ec960 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 924 (UIView.m:15859)
10  UIKitCore                       0x00000001841ea0f4 -[UIScrollView _didMoveFromWindow:toWindow:] + 96 (UIScrollView.m:2987)
11  UIKitCore                       0x00000001842ec960 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 924 (UIView.m:15859)
12  UIKitCore                       0x00000001841ea0f4 -[UIScrollView _didMoveFromWindow:toWindow:] + 96 (UIScrollView.m:2987)
13  UIKitCore                       0x00000001842ec960 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 924 (UIView.m:15859)
14  UIKitCore                       0x00000001842125cc __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 140 (UIView.m:12304)
15  CoreAutoLayout                  0x000000019a7555f8 -[NSISEngine withBehaviors:performModifications:] + 88 (NSISEngine.m:1988)
16  UIKitCore                       0x00000001842a2128 -[UIView(Hierarchy) _postMovedFromSuperview:] + 836 (UIView.m:471)
17  UIKitCore                       0x00000001841be194 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 2148 (UIView.m:16700)
18  business                        0x00000001028bd944 -[RNSScreenContainerView attachScreen:atIndex:] + 212 (RNSScreenContainer.m:130)
19  business                        0x00000001028bddf4 -[RNSScreenContainerView updateContainer] + 1072 (RNSScreenContainer.m:170)
20  business                        0x00000001028b8c54 -[RNSScreenView setActivityStateOrNil:] + 108 (RNSScreen.m:76)
21  business                        0x00000001028dc8d8 __49-[RCTComponentData createPropBlock:isShadowView:]_block_invoke.89 + 228 (RCTComponentData.m:300)
22  business                        0x00000001028dca8c __49-[RCTComponentData createPropBlock:isShadowView:]_block_invoke_2.90 + 364 (RCTComponentData.m:318)
23  business                        0x00000001028dccec __37-[RCTComponentData setProps:forView:]_block_invoke + 100 (RCTComponentData.m:356)
24  CoreFoundation                  0x0000000181bcc714 __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__ + 24 (NSDictionaryHelpers.m:10)
25  CoreFoundation                  0x0000000181be482c -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 208 (NSDictionaryM_Common.h:315)
26  business                        0x00000001028dcc68 -[RCTComponentData setProps:forView:] + 124 (RCTComponentData.m:355)
27  business                        0x000000010293041c -[RCTUIManager synchronouslyUpdateViewOnUIThread:viewName:props:] + 156 (RCTUIManager.m:1048)
28  business                        0x0000000102968490 -[RCTPropsAnimatedNode updateView] + 260 (RCTPropsAnimatedNode.m:75)
29  business                        0x0000000102968bb4 -[RCTPropsAnimatedNode performUpdate] + 840 (RCTPropsAnimatedNode.m:139)
30  business                        0x000000010295c79c -[RCTAnimatedNode updateNodeIfNecessary] + 264 (RCTAnimatedNode.m:106)
31  business                        0x0000000102964c54 0x10277c000 + 2002004
32  CoreFoundation                  0x0000000181bcc714 __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__ + 24 (NSDictionaryHelpers.m:10)
33  CoreFoundation                  0x0000000181be482c -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 208 (NSDictionaryM_Common.h:315)
34  business                        0x0000000102964708 0x10277c000 + 2000648
35  business                        0x0000000102935b18 RCTExecuteOnMainQueue + 44 (RCTUtils.m:258)
36  business                        0x000000010296292c -[RCTNativeAnimatedModule eventDispatcherWillDispatchEvent:] + 92 (RCTNativeAnimatedModule.mm:355)
37  business                        0x0000000102952b14 -[RCTEventDispatcher sendEvent:] + 212 (RCTEventDispatcher.mm:127)
38  business                        0x0000000102874c00 -[REAEventDispatcher sendEvent:] + 164 (REAEventDispatcher.m:11)
39  business                        0x0000000102849638 -[RNGestureHandler sendStateChangeEvent:] + 120 (RNGestureHandler.m:0)
40  business                        0x0000000102849590 -[RNGestureHandler sendEventsInState:forViewWithTag:withExtraData:] + 352 (RNGestureHandler.m:233)
41  business                        0x0000000102849408 -[RNGestureHandler handleGesture:] + 204 (RNGestureHandler.m:194)
42  UIKitCore                       0x0000000184212c14 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 56 (UIGestureRecognizer.m:136)
43  UIKitCore                       0x00000001841dbd48 _UIGestureRecognizerSendTargetActions + 116 (UIGestureRecognizer.m:1481)
44  UIKitCore                       0x00000001841a4a94 _UIGestureRecognizerSendActions + 284 (UIGestureRecognizer.m:1520)
45  UIKitCore                       0x00000001841de0f8 -[UIGestureRecognizer _updateGestureForActiveEvents] + 636 (UIGestureRecognizer.m:0)
46  UIKitCore                       0x0000000184196304 _UIGestureEnvironmentUpdate + 1988 (UIGestureEnvironment.m:206)
47  UIKitCore                       0x00000001841ca0b0 -[UIGestureEnvironment _updateForEvent:window:] + 784 (UIGestureEnvironment.m:1332)
48  UIKitCore                       0x00000001841d7250 -[UIWindow sendEvent:] + 4428 (UIWindow.m:3265)
49  UIKitCore                       0x0000000184387918 -[UIApplication sendEvent:] + 828 (UIApplication.m:11876)
50  UIKitCore                       0x00000001841aa464 __dispatchPreprocessedEventFromEventQueue + 7904 (UIEventDispatcher.m:2290)
51  UIKitCore                       0x000000018419f250 __processEventQueue + 6760 (UIEventDispatcher.m:2597)
52  UIKitCore                       0x00000001841a46fc __eventFetcherSourceCallback + 172 (UIEventDispatcher.m:2669)
53  CoreFoundation                  0x0000000181c470d0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 (CFRunLoop.c:1972)
54  CoreFoundation                  0x0000000181c57d90 __CFRunLoopDoSource0 + 208 (CFRunLoop.c:2016)
55  CoreFoundation                  0x0000000181b92098 __CFRunLoopDoSources0 + 268 (CFRunLoop.c:2053)
56  CoreFoundation                  0x0000000181b978a4 __CFRunLoopRun + 820 (CFRunLoop.c:2951)
57  CoreFoundation                  0x0000000181bab468 CFRunLoopRunSpecific + 600 (CFRunLoop.c:3268)
58  GraphicsServices                0x000000019d73638c GSEventRunModal + 164 (GSEvent.c:2200)
59  UIKitCore                       0x000000018454d088 -[UIApplication _run] + 1100 (UIApplication.m:3493)
60  UIKitCore                       0x00000001842cb958 UIApplicationMain + 2092 (UIApplication.m:5046)
61  business                        0x000000010278414c main + 88 (main.m:7)
62  dyld                            0x0000000103995aa4 start + 520 (dyldMain.cpp:879)

Package versions

name version
react-native 0.64.3
react-native-reanimated 0.23.1
NodeJS 14.17.5
Xcode 13.2.1
Java 1.8.0_301
Gradle 6.7.1
expo 44

Affected platforms

github-actions[bot] commented 2 years ago

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snippet of code, a snack or a link to a GitHub repository that reproduces the problem?

github-actions[bot] commented 2 years ago

Hey! 👋

It looks like you've omitted a few important sections from the issue template.

Please complete Snack or minimal code example and Description sections.

pistonsky commented 2 years ago

I have a similar situation. I'm using a build from TestFlight, play with the app for a while, minimize it, restore it a few times, then I tap somewhere (on a tab, on a button) and it freezes up. I attach it to debugger and pause it to see where does it loop, and I see this semaphore stuff:

Screenshot 2022-03-17 at 02 23 25 Screenshot 2022-03-17 at 02 23 39

This should be caused by a previous call to enqueueUpdateViewOnNativeThread with trySynchronously argument set to true, which happens only from updateProps when there are some whitelisted native props there. And updateProps is used in useAnimatedStyle everywhere.

There is a similar older ticket here - https://github.com/software-mansion/react-native-reanimated/issues/1284

zhiqingchen commented 2 years ago

This problem may be caused by react-native-screens, what's your react-native-screens version?

https://github.com/software-mansion/react-native-screens/issues/726

zhiqingchen commented 2 years ago

detachInactiveScreens false

anhquan291 commented 2 years ago

Thanks @zhiqingchen lets me try It's sad that I'm still facing the issue. react-native-screens version is 3.9.0 as well as the latest one 3.11.1. Thank you

anhquan291 commented 2 years ago

Hi @pistonsky , I'm facing exactly the same one. Did you find a solution for that issue? Really appreciate that if you could share. Thank you

"@react-navigation/bottom-tabs": "^6.0.9", "@react-navigation/core": "^6.1.0", "@react-navigation/native": "^6.0.6", "@react-navigation/stack": "^6.0.11", "react-native-reanimated": "~2.3.3", "react-native-screens": "^3.13.1"

AlessandroGenerale17 commented 2 years ago

We are experiencing the same issue on both iOS 15.2 simulator and a physical device.

package version
react-native 0.66.0
@react-navigation/native 6.0.6
@react-navigation/native-stack 6.2.4
@react-navigation/stack 6.0.11
react-native-gesture-handler 2.4.2

We have a simple stack navigator which has another nested stack navigator. When navigating normally (back button) from the first screen of the nested navigator everything works as expected. However, when swiping back to the previous screen, the app freezes and then crashes without a sign of an error message other than the local system stack trace. The stack trace is very similar to the ones posted earlier here.

Both navigators are created using the createStackNavigator method. If both are are changed to createNativeStackNavigator then there is no issue, but I do not want to use the Native stack as I need to alter some other properties on the screen.

Did someone find a solution for this?

khattab93 commented 2 years ago

I'm facing facing the same issue.

casaumayman commented 2 years ago

I'm facing facing the same issue.

vladanyes commented 1 year ago

After I removed these props from Animated.View the bug disappeared

key={isVisible}
entering={FadeIn}
exiting={FadeOut}
github-actions[bot] commented 1 year ago

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

Latropos commented 9 months ago

We are still unable to reproduce your problem. If anyone can provide a reproduction please feel free to reopen this issue

sarthakpranesh commented 1 month ago

Hi @Latropos @vladanyes I have been facing a similar issue in production. I have an Animated.View being rendered with exiting and entering animation right on app start (this is usually when JS thread struggles for 2-3s loading everything), this somehow freezes my app and ends up blocking my UI thread causing ANRs. Also I am able to see high CPU usage using Flashlight occurring on the UI thread. Converting this Animated.View to a normal View completely removes the ANR. Worth mentioning I am using latest reanimated v2, and its not possible to upgrade to v3 in near future.

This is what I get on embrace:

Thread Name: com.swmansion.reanimated.layoutReanimation.ReanimatedNativeHierarchyManager.manageChildren
  java.lang.System.arraycopy (Native Method)
  java.util.Arrays.copyOf (Arrays.java:3258)
  java.lang.AbstractStringBuilder.ensureCapacityInternal (AbstractStringBuilder.java:124)
  java.lang.AbstractStringBuilder.append (AbstractStringBuilder.java:448)
  java.lang.StringBuilder.append (StringBuilder.java:137)
  android.view.View.notifyAppearedOrDisappearedForContentCaptureIfNeeded (View.java:9676)
  android.view.View.dispatchDetachedFromWindow (View.java:20642)
  android.view.ViewGroup.dispatchDetachedFromWindow (ViewGroup.java:4005)
  android.view.ViewGroup.removeViewInternal (ViewGroup.java:5629)
  android.view.ViewGroup.removeViewAt (ViewGroup.java:5576)
  com.facebook.react.views.view.ReactViewGroup.removeViewAt (ReactViewGroup.java:545)
  com.facebook.react.views.view.ReactClippingViewManager.removeViewAt (ReactClippingViewManager.java:74)
  com.facebook.react.views.view.ReactClippingViewManager.removeViewAt (ReactClippingViewManager.java:19)
  com.swmansion.reanimated.layoutReanimation.ReanimatedNativeHierarchyManager.manageChildren (ReanimatedNativeHierarchyManager.java:310)
  com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute (UIViewOperationQueue.java:217)
  com.facebook.react.uimanager.UIViewOperationQueue$1.run (UIViewOperationQueue.java:915)
  com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches (UIViewOperationQueue.java:1026)
  com.facebook.react.uimanager.UIViewOperationQueue.access$2600 (UIViewOperationQueue.java:47)
  com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded (UIViewOperationQueue.java:1086)
  com.facebook.react.uimanager.GuardedFrameCallback.doFrame (GuardedFrameCallback.java:29)
  com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame (ReactChoreographer.java:175)
  com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame (ChoreographerCompat.java:85)
  android.view.Choreographer$CallbackRecord.run (Choreographer.java:972)
  android.view.Choreographer.doCallbacks (Choreographer.java:797)
  android.view.Choreographer.doFrame (Choreographer.java:728)
  android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:959)
  android.os.Handler.handleCallback (Handler.java:938)
  android.os.Handler.dispatchMessage (Handler.java:99)
  android.os.Looper.loop (Looper.java:223)
  android.app.ActivityThread.main (ActivityThread.java:7706)
  java.lang.reflect.Method.invoke (Native Method)
  com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:612)
  com.android.internal.os.ZygoteInit.main (ZygoteInit.java:997)

I'll try to share a small reproduction of this issue over the weekend, but I feel this is worth looking into.