WordPress-iOS icon indicating copy to clipboard operation
WordPress-iOS copied to clipboard

Crash when opening and closing the editor: C++ Exception: NSt3__112system_errorE

Open guarani opened this issue 2 years ago • 41 comments

Sentry issues:

Reference: Sentry search for NSt3__112system_errorE across both the JP and WP apps.

Potential solution

The crash should be addressed with https://github.com/wordpress-mobile/WordPress-iOS/pull/20956. More context.

Reproduction Steps

Copied from https://github.com/wordpress-mobile/WordPress-iOS/issues/20499#issuecomment-1593323859.

  1. Navigate to the post list screen.
  2. Focus the search input and query for several posts.
  3. Keep the search input focused.[^1]
  4. Open and close a post.
  5. Repeat step 4 until the app crashes.[^2]

[^1]: May not be necessary, but keyboard show/hide event are in numerous Sentry crash logs. [^2]: Crashing occurs very infrequently.

guarani avatar Apr 10 '23 19:04 guarani

This might be related to React Native because it appears in the Stack Trace I downloaded from Sentry, e.g.:

Thread 9 name: com.facebook.react.JavaScript
0   libsystem_kernel.dylib          0x3aef6567c         __psynch_cvwait
1   libsystem_pthread.dylib         0x3cfe34068         _pthread_cond_wait
2   JavaScriptCore                  0x35a738ce8         WTF::ParkingLot::parkConditionallyImpl
3   JavaScriptCore                  0x35a6f9638         WTF::Condition::waitUntilUnchecked<T>
4   JavaScriptCore                  0x35b177188         JSC::Heap::lastChanceToFinalize
5   JavaScriptCore                  0x35b7f8608         JSC::VM::~VM
6   JavaScriptCore                  0x35b68a068         JSC::JSLockHolder::~JSLockHolder
7   JavaScriptCore                  0x35ab857e4         JSGlobalContextRelease
8   WordPress                       0x2042d69c0         facebook::jsc::JSCRuntime::~JSCRuntime (JSCRuntime.cpp:392)
9   WordPress                       0x2042d6ac0         [inlined] facebook::jsc::JSCRuntime::~JSCRuntime (JSCRuntime.cpp:384)
10  WordPress                       0x2042d6ac0         facebook::jsc::JSCRuntime::~JSCRuntime (JSCRuntime.cpp:384)
11  WordPress                       0x203ca7bd0         [inlined] std::__1::__shared_count::__release_shared (shared_ptr.h:177)
12  WordPress                       0x203ca7bd0         [inlined] std::__1::__shared_weak_count::__release_shared (shared_ptr.h:219)
13  WordPress                       0x203ca7bd0         std::__1::shared_ptr<T>::~shared_ptr (shared_ptr.h:959)
14  WordPress                       0x203ed5128         [inlined] std::__1::shared_ptr<T>::~shared_ptr (shared_ptr.h:957)
15  WordPress                       0x203ed5128         reanimated::RuntimeManager::~RuntimeManager (RuntimeManager.h:36)
16  WordPress                       0x203ed7168         reanimated::NativeReanimatedModule::~NativeReanimatedModule (NativeReanimatedModule.h:26)
17  WordPress                       0x203ca7bd0         [inlined] std::__1::__shared_count::__release_shared (shared_ptr.h:177)
18  WordPress                       0x203ca7bd0         [inlined] std::__1::__shared_weak_count::__release_shared (shared_ptr.h:219)
19  WordPress                       0x203ca7bd0         std::__1::shared_ptr<T>::~shared_ptr (shared_ptr.h:959)
20  WordPress                       0x2042d9320         [inlined] std::__1::shared_ptr<T>::~shared_ptr (shared_ptr.h:957)
21  WordPress                       0x2042d9320         [inlined] facebook::jsc::detail::HostObjectProxyBase::~HostObjectProxyBase (JSCRuntime.cpp:703)
22  WordPress                       0x2042d9320         [inlined] facebook::jsc::JSCRuntime::createObject::HostObjectProxy::~HostObjectProxy (JSCRuntime.cpp:720)
23  WordPress                       0x2042d9320         [inlined] facebook::jsc::JSCRuntime::createObject::HostObjectProxy::~HostObjectProxy (JSCRuntime.cpp:720)
24  WordPress                       0x2042d9320         facebook::jsc::JSCRuntime::createObject::HostObjectProxy::finalize (JSCRuntime.cpp:825)

guarani avatar Apr 10 '23 19:04 guarani

👋 @geriux, do you have any context on this crash? I saw your name in the Activity tab of the Sentry issue for this crash. I bumped into this on Snetry during my release rotation because it's the top crash in 22.0, so I created this GitHub issue to help triage.

guarani avatar Apr 10 '23 19:04 guarani

👋 @geriux, do you have any context on this crash? I saw your name in the Activity tab of the Sentry issue for this crash. I bumped into this on Snetry during my release rotation because it's the top crash in 22.0, so I created this GitHub issue to help triage.

It looks like it is related to this issue https://github.com/WordPress/gutenberg/issues/41686 and the Reanimated library. After some investigations, we couldn't find a quick solution but we had some ideas like starting using Hermes on iOS or updating the Reanimated library to the latest version. I think we should revisit this as it is one of the top issues.

geriux avatar Apr 11 '23 07:04 geriux

Thanks for the context, @geriux!

guarani avatar Apr 11 '23 18:04 guarani

As for next steps, should someone be assigned to this issue? I should remove the Needs Triage label once it has an assignee (see internal ref PCYsg-vRg-p2).

guarani avatar Apr 11 '23 22:04 guarani

Maybe we should add it to the Maintenance Week board?

geriux avatar Apr 12 '23 16:04 geriux

Good idea! @tiagomar I understand that you're maintaining the maintenance board (see React Native board). Would this be a good candidate as @geriux suggested above?

guarani avatar Apr 12 '23 19:04 guarani

I assessed this as priority due to Medium severity (assuming drag & drop is a low priority feature) and Medium impact (unsure about it, but maybe 6-24% of users affected given the 101 events in last 24 hours).

guarani avatar Apr 12 '23 21:04 guarani

Do you think https://a8c.sentry.io/issues/3322079168 is a duplicate of the Sentry issue mentioned at the top of this issue, @geriux? I found them to have the same error, C++ Exception NSt3__112system_errorE but when viewing either of them, I couldn't get Sentry to list the other under the Similar Issues in order to merge them.

guarani avatar Apr 12 '23 21:04 guarani

Thanks for the ping @guarani! Yes, I think it is. I have just added this one to the board.

tiagomar avatar Apr 13 '23 14:04 tiagomar

Do you think https://a8c.sentry.io/issues/3322079168 is a duplicate of the Sentry issue mentioned at the top of this issue, @geriux? I found them to have the same error, C++ Exception NSt3__112system_errorE but when viewing either of them, I couldn't get Sentry to list the other under the Similar Issues in order to merge them.

Yeah, that's the same as the other one. That's weird that it doesn't show an option to merge them 🤔

But I can see in that issue that it also happens when the editor is closed.

geriux avatar Apr 13 '23 14:04 geriux

I just realized that the two Sentry issues are in different Sentry projects (WP vs. JP) so can't be merged 🤦:

Screenshot 2023-04-14 at 10 19 35

I linked both back to this GitHub issue 👍

guarani avatar Apr 14 '23 14:04 guarani

I just realized that the two Sentry issues are in different Sentry projects (WP vs. JP) so can't be merged 🤦:

😅 nice catch! Cool, thank you!

geriux avatar Apr 14 '23 14:04 geriux

@Guarani I removed the "Requires Triage" label as it appears this issue was prioritized and placed on the maintenance board. Please correct me if I am wrong. Thanks!

dcalhoun avatar Apr 17 '23 15:04 dcalhoun

Good call about removing the "Requires Triage" label, @dcalhoun!

guarani avatar Apr 19 '23 20:04 guarani

This PR might fix this issue in 22.4, although we'd need to confirm this by checking if we receive this Sentry event in version 22.4. So far during the beta testing, no issue was reported 🤞 .

fluiddot avatar May 23 '23 16:05 fluiddot

This PR might fix this issue in 22.4, although we'd need to confirm this by checking if we receive this Sentry event in version 22.4. So far during the beta testing, no issue was reported 🤞 .

I checked the Sentry events again now that version 22.4 is released, and seems the issue is still reported 😞. We'd need to investigate another solution.

fluiddot avatar May 30 '23 15:05 fluiddot

While I have not identified consistent reproduction steps, the few times I reproduced this it occurred while opening and closing posts. So, I am retitling this post to not directly reference dragging and dropping blocks.

Steps to reproduce:

  1. Navigate to the post list screen.
  2. Focus the search input and query for several posts.
  3. Keep the search input focused.[^1]
  4. Open and close a post.
  5. Repeat step 4 until the app crashes.[^2]

[^1]: May not be necessary, but keyboard show/hide event are in numerous Sentry crash logs. [^2]: Crashing occurs very infrequently.

If this crash does relate to react-native-reanimated, then it likely occurs in setup or teardown code executed when opening closing the post editor. E.g. keyboard-related animations (KeyboardAwareFlatList) or drag-and-drop logic.

dcalhoun avatar Jun 15 '23 15:06 dcalhoun

I still have not identified reproduction steps that work consistently. Obviously, that makes identifying the error origin difficult.

While we know the editor is involved via the reproduction steps and JavaScript activity in the number 9 stack trace thread — not the crashed thread, which is reported as number 0 — I will note it is possible the error origin resides in logic unrelated to React Native, e.g. passing initial data to the editor, managing UIKit views.

Removing my assignment while I turn my attention to other projects for the foreseeable future.

dcalhoun avatar Jun 19 '23 13:06 dcalhoun

👋 Hey @dcalhoun, I see you're still assigned here and this is in-progress on the GitHub board, should this be updated?

guarani avatar Jun 19 '23 18:06 guarani

Thanks for the ping. I overlooked updating the issue. 🙇🏻

dcalhoun avatar Jun 19 '23 18:06 dcalhoun

👋 @fluiddot, based on https://github.com/WordPress/gutenberg/pull/52320, it looks like this might be fixed in 22.8. I've changed the status here to Monitoring and will check back to see if the issue persists or not. Please let me know if that sounds like a plan 👍

guarani avatar Jul 12 '23 16:07 guarani

👋 @fluiddot, based on WordPress/gutenberg#52320, it looks like this might be fixed in 22.8. I've changed the status here to Monitoring and will check back to see if the issue persists or not. Please let me know if that sounds like a plan 👍

Sounds great, thanks @guarani for updating its status.

fluiddot avatar Jul 12 '23 16:07 fluiddot

Just looping back here to say that there's been no reoccurrence of this crash in the 22.8 beta so far. However, it's too early to tell if this is fixed because this crash only happened once in the 22.7 beta before happening 244 times once 22.7 was in production.

guarani avatar Jul 20 '23 16:07 guarani

Unfortunately, there're new events for both JPiOS 22.8 and WPiOS 22.8.

We need to review the new reports and look for further solutions.

staskus avatar Jul 25 '23 07:07 staskus

Unfortunately, there're new events for both JPiOS 22.8 and WPiOS 22.8.

😞

We need to review the new reports and look for further solutions.

The fix we incorporated for this was related to being able to identify a similar crash when upgrading React Native. It was a long shot using the same fix for the current React Native version, but we had to try. Hopefully, with the RN upgrade that includes a newer version of the Reanimated library, and the fact that we'll be also enabling Hermes, maybe the crash situation improve. The main problem with this crash is that we aren't able to reproduce it consistently. In any case, since we identified a reproduction case, we could confirm if it's reproducible in the new RN version.

fluiddot avatar Jul 25 '23 08:07 fluiddot

Thanks for a quick reply, @fluiddot!

Hopefully, with the RN upgrade that includes a newer version of the Reanimated library, and the fact that we'll be also enabling Hermes, maybe the crash situation improve.

Just to clarify, these updates were shipped together with 22.8? Or are there any further updates incoming that could potentially reduce occurrences of this crash?

staskus avatar Jul 25 '23 08:07 staskus

Just to clarify, these updates were shipped together with 22.8? Or are there any further updates incoming that could potentially reduce occurrences of this crash?

No, sorry. The changes I mentioned (i.e. the React Native upgrade) that could reduce occurrences aren't merged yet, they will be part of next version 23.0.

fluiddot avatar Jul 25 '23 08:07 fluiddot

No, sorry. The changes I mentioned (i.e. the React Native upgrade) that could reduce occurrences aren't merged yet, they will be part of next version 23.0.

Got it, thanks for the update! We'll continue monitoring the issue in upcoming releases then.

staskus avatar Jul 25 '23 09:07 staskus

Testing on trunk

💣 Managed to reproduce the crash consistently by automating these steps:

graph LR
A(Select the search bar)
A --> B(Open post)
B --> C(Dismiss post)
C --> A

After a couple of minutes I consistently get the crash matching the Sentry reports:

Stack trace
com.facebook.react.JavaScript (26)#0	0x00000001eefb2558 in __pthread_kill ()
#1	0x000000020fdf7118 in pthread_kill ()
#2	0x00000001b7597178 in abort ()
#3	0x00000001b75ef0a4 in __assert_rtn ()
#4	0x00000001030eab14 in facebook::jsc::JSCRuntime::cloneObject(facebook::jsi::Runtime::PointerValue const*) at /Users/povilasstaskus/Projects/WordPress-iOS/Pods/React-jsi/JSCRuntime.cpp:617
#5	0x0000000102855858 in facebook::jsi::Value::Value(facebook::jsi::Runtime&, facebook::jsi::Object const&) at /Users/povilasstaskus/Projects/WordPress-iOS/Pods/React-jsi/jsi/jsi.h:1005
#6	0x000000010285580c in facebook::jsi::Value facebook::jsi::detail::toValue<facebook::jsi::Object>(facebook::jsi::Runtime&, facebook::jsi::Object const&) at /Users/povilasstaskus/Projects/WordPress-iOS/Pods/React-jsi/jsi/jsi-inl.h:40
#7	0x00000001028a2804 in void facebook::jsi::Object::setProperty<facebook::jsi::Object&>(facebook::jsi::Runtime&, facebook::jsi::String const&, facebook::jsi::Object&) at /Users/povilasstaskus/Projects/WordPress-iOS/Pods/React-jsi/jsi/jsi-inl.h:117
#8	0x00000001028a223c in reanimated::ShareableValue::toJSValue(facebook::jsi::Runtime&)::$_2::operator()(facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long) at /Users/povilasstaskus/Projects/WordPress-iOS/Pods/RNReanimated/Common/cpp/SharedItems/ShareableValue.cpp:387
#9	0x00000001028a218c in decltype(std::declval<reanimated::ShareableValue::toJSValue(facebook::jsi::Runtime&)::$_2&>()(std::declval<facebook::jsi::Runtime&>(), std::declval<facebook::jsi::Value const&>(), std::declval<facebook::jsi::Value const*>(), std::declval<unsigned long>())) std::__1::__invoke[abi:v15006]<reanimated::ShareableValue::toJSValue(facebook::jsi::Runtime&)::$_2&, facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long>(reanimated::ShareableValue::toJSValue(facebook::jsi::Runtime&)::$_2&, facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*&&, unsigned long&&) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.4.sdk/usr/include/c++/v1/__functional/invoke.h:394
#10	0x00000001028a2114 in facebook::jsi::Value std::__1::__invoke_void_return_wrapper<facebook::jsi::Value, false>::__call<reanimated::ShareableValue::toJSValue(facebook::jsi::Runtime&)::$_2&, facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long>(reanimated::ShareableValue::toJSValue(facebook::jsi::Runtime&)::$_2&, facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*&&, unsigned long&&) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.4.sdk/usr/include/c++/v1/__functional/invoke.h:470
#11	0x00000001028a20c8 in std::__1::__function::__alloc_func<reanimated::ShareableValue::toJSValue(facebook::jsi::Runtime&)::$_2, std::__1::allocator<reanimated::ShareableValue::toJSValue(facebook::jsi::Runtime&)::$_2>, facebook::jsi::Value (facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long)>::operator()[abi:v15006](facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*&&, unsigned long&&) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.4.sdk/usr/include/c++/v1/__functional/function.h:185
#12	0x00000001028a0e4c in std::__1::__function::__func<reanimated::ShareableValue::toJSValue(facebook::jsi::Runtime&)::$_2, std::__1::allocator<reanimated::ShareableValue::toJSValue(facebook::jsi::Runtime&)::$_2>, facebook::jsi::Value (facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long)>::operator()(facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*&&, unsigned long&&) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.4.sdk/usr/include/c++/v1/__functional/function.h:359
#13	0x00000001030f259c in std::__1::__function::__value_func<facebook::jsi::Value (facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long)>::operator()[abi:v15006](facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*&&, unsigned long&&) const at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.4.sdk/usr/include/c++/v1/__functional/function.h:512
#14	0x00000001030f1fa0 in std::__1::function<facebook::jsi::Value (facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long)>::operator()(facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long) const at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.4.sdk/usr/include/c++/v1/__functional/function.h:1197
#15	0x00000001030f179c in facebook::jsc::JSCRuntime::createFunctionFromHostFunction(facebook::jsi::PropNameID const&, unsigned int, std::__1::function<facebook::jsi::Value (facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long)>)::HostFunctionMetadata::call(OpaqueJSContext const*, OpaqueJSValue*, OpaqueJSValue*, unsigned long, OpaqueJSValue const* const*, OpaqueJSValue const**) at /Users/povilasstaskus/Projects/WordPress-iOS/Pods/React-jsi/JSCRuntime.cpp:1166
#16	0x00000001c3c7b780 in <redacted> ()
#17	0x00000001c4620e28 in <redacted> ()
#18	0x00000001c46684d4 in <redacted> ()
#19	0x00000001c3c03aa0 in <redacted> ()
Code example (Edited PostListViewController.swift)
     private func editPost(apost: AbstractPost) {
      guard let post = apost as? Post else {
          return
      }
      
      iteratePresentingPost(post: post)
  }
  
  private func iteratePresentingPost(post: Post) {
      PostListEditorPresenter.handle(post: post, in: self, entryPoint: .postsList)
      
      DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
          self.dismiss(animated: false)
          
          DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
              self.searchController.searchBar.becomeFirstResponder()
              DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
                  self.iteratePresentingPost(post: post)
              }
          }
      }
  }

Testing with updated RN version

After multiple runs confirming the crash is reproducible, I switched to a gutenberg/upgrade/react-native-0.71.11 branch.

✅ I wasn't able to reproduce this particular crash anymore on multiple long runs. The evidence points that when https://github.com/wordpress-mobile/WordPress-iOS/pull/20956 gets merged this particular issue will be resolved.

Unfortunately, two times I jumped on a different crash when repeating the same steps. It didn't happen reliably for me. I informed @fluiddot about it:

Unhandled JS Exception: TypeError: Cannot read property 'map' of undefined, js engine: hermes, stack:
 2023-07-26 17:51:48.751334+0300 Jetpack[97864:5674874] [native] Unable to find module for RedBox
2023-07-26 17:51:48.751822+0300 Jetpack[97864:5674874] [native] Unhandled JS Exception: TypeError: Cannot read property 'map' of undefined, js engine: hermes
2023-07-26 17:51:48.753797+0300 Jetpack[97864:5674874] *** Terminating app due to uncaught exception 'RCTFatalException: Unhandled JS Exception: TypeError: Cannot read property 'map' of undefined, js engine: hermes', reason: 'Unhandled JS Exception: TypeError: Cannot read property 'map' of undefined, js engine: hermes, stack:
anonymous@1:3209554
value@1:164730
anonymous@1:163142
value@1:164005
value@1:163104
'
*** First throw call stack:
(0x1b0070cb4 0x1a910c3d0 0x10ecafe48 0x10ebe56ac 0x10ebe5ef0 0x1b00d9c04 0x1b0087cb4 0x1b00876cc 0x10ecdb398 0x10ecdd44c 0x10ecdd09c 0x10d4a0520 0x10d4a2038 0x10d4aa0b0 0x10d4aadf4 0x10d4b7c74 0x20fdf0ddc 0x20fdf0b7c)
libc++abi: terminating due to uncaught exception of type NSException


#0	0x000000010d4a6d10 in dispatch_async ()
#1	0x000000010ecdce84 in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int) ()
#2	0x000000010ed69aac in facebook::react::JsToNativeBridge::callNativeModules(facebook::react::JSExecutor&, folly::dynamic&&, bool) ()
#3	0x000000010edd9750 in facebook::react::JSIExecutor::callNativeModules(facebook::jsi::Value const&, bool) ()
#4	0x000000010edd98f8 in facebook::react::JSIExecutor::invokeCallback(double, folly::dynamic const&) ()
#5	0x000000010ed6b04c in std::__1::__function::__func<facebook::react::NativeToJsBridge::runOnExecutorQueue(std::__1::function<void (facebook::react::JSExecutor*)>)::$_8, std::__1::allocator<facebook::react::NativeToJsBridge::runOnExecutorQueue(std::__1::function<void (facebook::react::JSExecutor*)>)::$_8>, void ()>::operator()() ()
#6	0x000000010ecc8b30 in facebook::react::tryAndReturnError(std::__1::function<void ()> const&) ()
#7	0x000000010ecd43f0 in facebook::react::RCTMessageThread::tryFunc(std::__1::function<void ()> const&) ()
#8	0x000000010ecd41c8 in invocation function for block in facebook::react::RCTMessageThread::runAsync(std::__1::function<void ()>) ()
#9	0x00000001b00aa6e0 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ ()
#10	0x00000001b0111210 in __CFRunLoopDoBlocks ()
#11	0x00000001b00e1718 in __CFRunLoopRun ()
#12	0x00000001b00e63ec in CFRunLoopRunSpecific ()
#13	0x000000010ecbe690 in +[RCTCxxBridge runRunLoop] ()
#14	0x00000001aa37c544 in __NSThread__start__ ()
#15	0x000000020fdf16b8 in _pthread_start ()
#16	0x000000020fdf0b88 in thread_start ()

staskus avatar Jul 26 '23 16:07 staskus