Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent freezing on iOS #2244

Closed
1 of 3 tasks
lucasjohnston opened this issue Jul 30, 2021 · 28 comments
Closed
1 of 3 tasks

Inconsistent freezing on iOS #2244

lucasjohnston opened this issue Jul 30, 2021 · 28 comments
Assignees
Labels
Bug bug-bash-jan22 Issues visited during Bug Bash Jan 2022 Missing repro This issue need minimum repro scenario 🏠 Reanimated 2 Release blocker

Comments

@lucasjohnston
Copy link

Description

Apologies in advance for vagueness, pretty hard to debug this one.

For the past few weeks I've been experiencing random freezing of our app, where the app seemingly stops in its tracks with no crashing/stacktrace/error. Initially I thought this was due to excessive re-rendering or a memory leak, but after reworking our logic to background actions the random freezes continue.
Could well still be an error on our side, but struggling to see where/how.

I've tried to debug this myself with little joy (can't remotely debug with reanimated) - the only nuggets of information I've managed to link are EXC_BAD_ACCESS exceptions which all seem to come from reanimated.

For reference, we're using both react-native's Animated and reanimated (in different parts of the app), and also frequently use Modalize which itself uses reanimated.

I found a previous issue that looks pretty similar to this but was fixed last year: #1284

Expected behavior

No freezes

Actual behavior & steps to reproduce

Unknown

Snack or minimal code example

Can't provide a replication unfortunately, but can provide some Sentry error traces from these exceptions.

EXC_BAD_ACCESS
XTUM > Stack overflow in _ZNKSt3__116__hash_node_baseIPNS_11__hash_nodeINS_17__hash_value_typeIiNS_6vectorINS_10shared_ptrIN8facebook3jsi5ValueEEENS_9allocatorIS8_EEEEEEPvEEE6__hashEv
Called from reanimated::StoreUser::~StoreUser::lambda::operator()
EXC_BAD_ACCESS
targetTimestamp > Attempted to dereference garbage pointer 0xce990e2ba698.
Called from reanimated::createReanimatedModule::lambda::operator()
EXC_BAD_ACCESS
Exception 1, Code 2752, Subcode 8 > Attempted to dereference garbage pointer 0xac0.
Called from reanimated::createReanimatedModule::lambda::operator()

Package versions

  • React Native: 0.64.1
  • React Native Reanimated: ^2.2.0
  • NodeJS: v14.15.5
  • Xcode: 12.5.1 (12E507)
  • Java & Gradle: Not relevant, we're iOS only

For reference

  • react-native-modalize: ^2.0.8
  • react-native-portalize: ^1.0.7
  • react-native-screens: 2.17.1
  • @react-navigation/native: ^5.9.2
  • @react-navigation/stack: ^5.14.2

Affected platforms

  • Android
  • iOS
  • Web
@github-actions
Copy link

Issue validator

The issue is valid!

@tankers746
Copy link

Getting a similar problem

Screen Shot 2021-08-05 at 5 30 58 pm

@happyfloat
Copy link

Maybe my problem is related, but it only started happening with alpha3 not alpha2:
#2366

@wanderlust252
Copy link

i've crash cause of useAnimatedReaction. EXC_BAD_ACCESS

@Sanglepp
Copy link

Sanglepp commented Oct 4, 2021

This happens to me with 2.3.0-beta.2. Common pattern to reach the issue is when I open a modal and close it. After that the UI is all freezed up. Issue dissapears when downgrading to 2.3.0-alpha.2.

@piaskowyk piaskowyk added the Important This seem to be a serious issue and we will need to take a deeper look into it some time soon label Oct 5, 2021
@piaskowyk piaskowyk self-assigned this Oct 5, 2021
@effektsvk
Copy link

@Sanglepp This might be completely separate issue, but I upgraded react-native to 0.66.0 (react-native-reanimated as well) and I started having similar issues with Modal too. It looks like a RN bug, more info here: facebook/react-native#32329. Just wanted to let you know.

@sergio-sanz
Copy link

I have the same problem with 2.3.0-alpha.3 and above. I'm using Layout Animations. Could be related with this API?

@dotansimha
Copy link

dotansimha commented Oct 11, 2021

As stated here before by @effektsvk - this seems to be related to facebook/react-native#32329

This causes issues with all libraries that are using Reanimated 2 for animations, starting from RN 0.65.1 (react-native-modal, react-native-screens, react-navigation and a few more).

Seems like it's something with the transition that keeps the native screen in memory, and on top of the main view, leading to an overlay that prevents touch events.

@piaskowyk @Szymon20000 , I saw you were working on RN~66 support in #2462 - any idea what could be done to workaround this issue? Any plan for a fix?

@Dmitry-GH
Copy link

I can confirm that I also had this issue with "react-native-reanimated": "^2.3.0-beta.2" and "react-native": "0.66.0".
I fixed this by downgrading these two, so my current config alongside other libraries:

"react-native": "0.65.1",
"react-native-reanimated": "^2.2.2",
"react-native-modal": "^13.0.0",
"react-native-screens": "^3.8.0",
"react-native-gesture-handler": "~1.10.3",
"react-native-tab-view": "^3.1.1",
"@react-navigation/bottom-tabs": "^6.0.7",
"@react-navigation/elements": "^1.1.2",
"@react-navigation/material-top-tabs": "^6.0.4",
"@react-navigation/native": "^6.0.4",
"@react-navigation/stack": "^6.0.9"

@effektsvk
Copy link

Hey, just a small note, there's new 2.2.3 version that should help for now.

@novev9
Copy link

novev9 commented Oct 17, 2021

I can confirm that updating to [email protected] fixes this issue.

@terrysahaidak
Copy link
Contributor

Anyone reporting this try this patch. You can edit these files directly from xcode in Development Pods directory.

7883fc1

@princefishthrower
Copy link

I can also confirm that 2.2.3 does work, while 2.3.0-beta.2 does not- is there a regression here?

@parasharrajat
Copy link

Any idea on how we can fix this for 2.3.x?

@hukpo
Copy link

hukpo commented Nov 4, 2021

@effektsvk Hey, so it works well with RN 0.66 and reanimated 2.2.3?

@effektsvk
Copy link

@effektsvk Hey, so it works well with RN 0.66 and reanimated 2.2.3?

@hukpavlo Yes, I didn't have any issues with those versions, and lot of others said that it's working fine for them as well in the RN thread (facebook/react-native#32329 (comment))

@numandev1
Copy link
Contributor

numandev1 commented Jan 26, 2022

I am using [email protected], [email protected] and [email protected] and having the same issue from the sentry log
but it is triggering from react-native-screens

EXC_BAD_ACCESS: __reanimatedHostObjectRef >
Attempted to dereference garbage pointer 0x8.
  OnShobbak           0x100ea9264  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3d08  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ea19f4  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3b64  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed23ec  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3d08  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ea19f4  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3b64  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed2ed8  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3d08  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ea19f4  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3b64  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed2ed8  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3d08  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ea19f4  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3b64  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed23ec  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100ed3d08  folly::Try<T>::throwUnlessValue
  OnShobbak           0x100eb16e8  folly::Try<T>::throwUnlessValue
  OnShobbak           0x101018138  _ZN5folly6detail8function9execSmallIZNS_7futures6detail4CoreINS_4UnitEE11setCallbackIZNS4_10FutureBaseIS6_E18thenImplementationIZNRS_6FutureIS6_E3viaENS_8Executor9KeepAliveISE_EEEUlOSG_ONS_3TryIS6_EEE_NS4_25tryExecutorCallableResultIS6_SL_vEEEENSt3__19e...
  hermes              0x1027d90f4  facebook::hermes::debugger::Debugger::jsiValueFromHermesValue
  hermes              0x1027d8aa0  facebook::hermes::debugger::Debugger::jsiValueFromHermesValue
  hermes              0x1027e77b8  facebook::jsi::JSError::~JSError
  hermes              0x1028013dc  facebook::jsi::JSError::~JSError
  hermes              0x102802d50  facebook::jsi::JSError::~JSError
  hermes              0x102802490  facebook::jsi::JSError::~JSError
  hermes              0x1027e79cc  facebook::jsi::JSError::~JSError
  hermes              0x1027e63ec  facebook::jsi::JSError::~JSError
  hermes              0x10285a954  facebook::jsi::JSError::~JSError
  hermes              0x1027e77b8  facebook::jsi::JSError::~JSError
  hermes              0x1028013dc  facebook::jsi::JSError::~JSError
  hermes              0x102802d50  facebook::jsi::JSError::~JSError
  hermes              0x102802490  facebook::jsi::JSError::~JSError
  hermes              0x1027e79cc  facebook::jsi::JSError::~JSError
  hermes              0x1027e7330  facebook::jsi::JSError::~JSError
  hermes              0x1028013ec  facebook::jsi::JSError::~JSError
  hermes              0x102802d50  facebook::jsi::JSError::~JSError
  hermes              0x102802490  facebook::jsi::JSError::~JSError
  hermes              0x1027e79cc  facebook::jsi::JSError::~JSError
  hermes              0x1027e7330  facebook::jsi::JSError::~JSError
  hermes              0x1028013ec  facebook::jsi::JSError::~JSError
  hermes              0x102802d50  facebook::jsi::JSError::~JSError
  hermes              0x102802490  facebook::jsi::JSError::~JSError
  hermes              0x1027e79cc  facebook::jsi::JSError::~JSError
  hermes              0x1027e684c  facebook::jsi::JSError::~JSError
  hermes              0x1028887a0  facebook::jsi::JSError::~JSError
  hermes              0x1027e77b8  facebook::jsi::JSError::~JSError
  hermes              0x1028013dc  facebook::jsi::JSError::~JSError
  hermes              0x102802d50  facebook::jsi::JSError::~JSError
  hermes              0x102802490  facebook::jsi::JSError::~JSError
  hermes              0x1027e79cc  facebook::jsi::JSError::~JSError
  hermes              0x1027e684c  facebook::jsi::JSError::~JSError
  hermes              0x1028887a0  facebook::jsi::JSError::~JSError
  hermes              0x1027e77b8  facebook::jsi::JSError::~JSError
  hermes              0x1028013dc  facebook::jsi::JSError::~JSError
  hermes              0x102802d50  facebook::jsi::JSError::~JSError
  hermes              0x102802490  facebook::jsi::JSError::~JSError
  hermes              0x1027e79cc  facebook::jsi::JSError::~JSError
  hermes              0x1027e7330  facebook::jsi::JSError::~JSError
  hermes              0x1027d1aac  facebook::hermes::HermesRuntime::rootsListLength
  OnShobbak           0x10101706c  _ZN5folly6detail8function9execSmallIZNS_7futures6detail4CoreINS_4UnitEE11setCallbackIZNS4_10FutureBaseIS6_E18thenImplementationIZNRS_6FutureIS6_E3viaENS_8Executor9KeepAliveISE_EEEUlOSG_ONS_3TryIS6_EEE_NS4_25tryExecutorCallableResultIS6_SL_vEEEENSt3__19e...
  OnShobbak           0x1010481f8  folly::exception_wrapper::InPlace<T>::get_exception_ptr_
  OnShobbak           0x10104805c  folly::exception_wrapper::InPlace<T>::get_exception_ptr_
  OnShobbak           0x100ed927c  facebook::react::JSIExecutor::defaultTimeoutInvoker
  OnShobbak           0x1010455f8  folly::exception_wrapper::InPlace<T>::get_exception_ptr_
  OnShobbak           0x100ff0238  facebook::react::JSIExecutor::defaultTimeoutInvoker
  OnShobbak           0x100f3d278  facebook::react::JSIExecutor::defaultTimeoutInvoker
  OnShobbak           0x100f496e0  facebook::react::JSIExecutor::defaultTimeoutInvoker
  OnShobbak           0x100f49494  facebook::react::JSIExecutor::defaultTimeoutInvoker
  CoreFoundation      0x1806be9d0  __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__
  CoreFoundation      0x1806bf8cc  __CFRunLoopDoBlocks
  CoreFoundation      0x180657c2c  __CFRunLoopRun
  CoreFoundation      0x18066b464  CFRunLoopRunSpecific
  OnShobbak           0x100f324d4  facebook::react::JSIExecutor::defaultTimeoutInvoker
  Foundation          0x181ed7408  __NSThread__start__
  libsystem_pthread   0x1f10bb9a0  _pthread_start

image

@jakub-gonet jakub-gonet added bug-bash-jan22 Issues visited during Bug Bash Jan 2022 Missing repro This issue need minimum repro scenario labels Jan 28, 2022
@kmagiera
Copy link
Member

Hi all! Thanks for reporting and all your comments. I wanted to point out that "EXC_BAD_ACCESS" is a typical error message related to accessing corrupted/cleaned-up/out-of-scope memory and even thought a lot of errors do have that message in common there are likely unrelated to each other.

We are commited to fixing all bugs that result in EXC_BAD_ACCESS error but we need to collect related causes under one issue and filter out the remaining ones. Since this issue was originally reported by @lucasjohnston and I saw some comments later on that 2.3 has fixes this problem for others wanted to ask if this problem still persist in 2.3 and after?

I also suspect that @tankers746's issue is related as it has a very similar trace (tracing to StoreUser class). As for the remaining commenters I can't tell for sure if your crash is related and therefore ask you to share more details and possibly open a new issue if if you don't see StoreUser on the trace in your case. Specifically the last comment by @nomi9995 is likely an unrelated issue as it happens in a different method and should be reported separately with all the details that would allow us to trace is down.

@kmagiera kmagiera added the Close when stale This issue is going to be closed when there is no activity for a while label Jan 28, 2022
@kmagiera kmagiera removed the Important This seem to be a serious issue and we will need to take a deeper look into it some time soon label Jan 28, 2022
@lucasjohnston
Copy link
Author

lucasjohnston commented Feb 15, 2022

Hi @kmagiera - I recently revisited my build and upgraded the package to 2.3 and observe exactly the same behaviour as before. Would be great to see some movement on this as there's been little progress on this issue (beyond other users reporting similar bugs) afaik. Let me know if there's anything I can provide to assist

@github-actions github-actions bot removed the Close when stale This issue is going to be closed when there is no activity for a while label Feb 15, 2022
@pfeiffer
Copy link

pfeiffer commented Mar 4, 2022

We're also seeing this issue with [email protected], [email protected] and [email protected]. It's not easily reproducible, but closing a modal will sometimes freeze the UI.

We have observed this both with and without Flipper added to the project (so probably unrelated to facebook/flipper#1399)

@lucasjohnston
Copy link
Author

I've trawled through a variety of issues trying to diagnose this (see #1284 #2775 #2327).

Today I found the component causing trouble - an Animated Gradient I'd built a year back and forgotten about.
The code is here: https://gist.github.com/lucasjohnston/fa6e9c66092664dcef09c42d5149087d
It roughly does the following:

  • Create a gradient multiples times bigger than the element (defaults to 6x)
  • Uses a custom function called "interpolate" to set an X,Y co-ordinate
  • Applies useAnimatedStyle() to the <View /> to transform to those co-ordinates
  • Uses the useAnimatedStyle func to trigger a callback on the "interpolate" func on the JS thread, using Shared Values, to trigger an animation to a new set of co-ordinates
  • When generating new X,Y co-ordinates, the angles between the last and current set are compared to ensure it doesn't look like the animation is just going back and forth in the same direction. The diff must be >15 or <-15.

When using the component, typically after ~5mins of running or immediately when starting to run, the random XY coordinates generated become very small and it takes >50 attempts to find an angle diff big enough. Normally this loop completes after just 1 or 2 attempts. I think this is down to the way RN / iOS handles randomness.

Screenshot 2022-03-31 at 20 21 23

It seems this is what causes the app to freeze up – I don't get why, though.
The component uses runOnJS() so shouldn't be doing anything to stop the UI thread, and it's called as a 'worklet' from useAnimatedStyle() so shouldn't be blocking the main JS thread either? None of the code depends on a transform to be made.

Screenshot 2022-03-31 at 20 06 47

It might loop multiple times, but the console reports shows that my interpolate func does still resolve the loop. The app continues to be frozen though, and Xcode highlights the getProperty() of a SharableValue when paused.

Screenshot 2022-03-31 at 14 57 57

My expectation was that an infinitely loop would freeze, but a resolved loop would ultimately resolve itself even if there's some lag. I'd also expect the app to crash, or RN to report some sort of error. None of this happens.

My guess is this being something to do with the way useAnimatedStyle().callback and runOnJS interact when a function is using Reanimated Shared Values.

Anyway – to avoid this, I've just removed the loop. If the angle isn't big enough, we just add some arbitrary values to the XY coords and hope for the best.

@lucasjohnston
Copy link
Author

Xcode 14 beta 4 is reporting a "Hang Risk" from RCTWebSocket, which I've raised separately (facebook/react-native#34400).
Probably irrelevant, but given all our app hangs have found their way back to Reanimated, I thought it worth mentioning.

@kostas64
Copy link

kostas64 commented Dec 5, 2022

I dont know what is your code that produces this error, but i was facing the same issue when i was using Gesture Detectors.

"react-native-gesture-handler": "^2.4.0"
"react-native-reanimated": "^2.10.0"

What didnt work:
Updating react-native-reantimated from 2.10.0 -> 2.13.0
Enabling Hermes Engine.

Code that made my app freeze (iOS, Android)

const pangGesture = Gesture.Pan()
.onUpdate(e => {
const leafsLength = Math.floor(e.x / 42);
runOnJS(onPressHandler)(leafsLength);
})
.onEnd(() => runOnJS(getRatedColor)());

By chaining runOnJS(true) to detector solved my issue.
const pangGesture = Gesture.Pan()
.runOnJS(true)
.onUpdate(e => {
const leafsLength = Math.floor(e.x / 42);
runOnJS(onPressHandler)(leafsLength);
})
.onEnd(() => runOnJS(getRatedColor)());

@cherucole
Copy link

Code that made my app freeze (iOS, Android)

const pangGesture = Gesture.Pan() .onUpdate(e => { const leafsLength = Math.floor(e.x / 42); runOnJS(onPressHandler)(leafsLength); }) .onEnd(() => runOnJS(getRatedColor)());

By chaining runOnJS(true) to detector solved my issue. const pangGesture = Gesture.Pan() .runOnJS(true) .onUpdate(e => { const leafsLength = Math.floor(e.x / 42); runOnJS(onPressHandler)(leafsLength); }) .onEnd(() => runOnJS(getRatedColor)());

Had the same setup and the suggestion above worked for me. Yet to test other devices but mine is working with no issues. Thank you

@kostas64
Copy link

Code that made my app freeze (iOS, Android)
const pangGesture = Gesture.Pan() .onUpdate(e => { const leafsLength = Math.floor(e.x / 42); runOnJS(onPressHandler)(leafsLength); }) .onEnd(() => runOnJS(getRatedColor)());
By chaining runOnJS(true) to detector solved my issue. const pangGesture = Gesture.Pan() .runOnJS(true) .onUpdate(e => { const leafsLength = Math.floor(e.x / 42); runOnJS(onPressHandler)(leafsLength); }) .onEnd(() => runOnJS(getRatedColor)());

Had the same setup and the suggestion above worked for me. Yet to test other devices but mine is working with no issues. Thank you

You are welcome :D

@MikhailVasiliev
Copy link

@kostas64 , it looks like it works for me as well, thanks

@kostas64
Copy link

@MikhailVasiliev happy to hear that!

@piaskowyk
Copy link
Member

Problem resolved since version 3.+, so I encourage to upgrade 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug bug-bash-jan22 Issues visited during Bug Bash Jan 2022 Missing repro This issue need minimum repro scenario 🏠 Reanimated 2 Release blocker
Projects
None yet
Development

No branches or pull requests