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

[iOS] Crash EXC_BAD_ACCESS (KERN_INVALID_ADDRESS) on webview unmounting #3025

Closed
Minishlink opened this issue Jun 28, 2023 · 8 comments
Closed

Comments

@Minishlink
Copy link

Minishlink commented Jun 28, 2023

Bug description:

Hello, we have these crash reports on Crashlytics after an upgrade from 11.23.1 to 13.2.1

EXC_BAD_ACCESS (KERN_INVALID_ADDRESS) 0x000000000000001e
Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x9af0 object_isClass + 16
1  Foundation                     0x8090 KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED + 72
2  Foundation                     0x3f9f8 NSKeyValueWillChangeWithPerThreadPendingNotifications + 296
3  WebKit                         0x430b6c WebKit::PageClientImplCocoa::gpuProcessDidExit() + 44
4  WebKit                         0x658748 WebKit::WebProcessPool::gpuProcessExited(int, WebKit::ProcessTerminationReason) + 488
5  WebKit                         0x6e4f54 WebKit::GPUProcessProxy::gpuProcessExited(WebKit::ProcessTerminationReason) + 216
6  WebKit                         0x6e50cc WebKit::GPUProcessProxy::processIsReadyToExit() + 136
7  WebKit                         0x1d6e98 WebKit::GPUProcessProxy::didReceiveMessage(IPC::Connection&, IPC::Decoder&) + 200
8  WebKit                         0x415f10 IPC::Connection::dispatchMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder> >) + 260
9  WebKit                         0x418c1c WTF::Detail::CallableWrapper<IPC::Connection::enqueueIncomingMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder> >)::$_13, void>::call() + 188
10 JavaScriptCore                 0x51b58 WTF::RunLoop::performWork() + 200
11 JavaScriptCore                 0x52890 WTF::RunLoop::performWork(void*) + 36
12 CoreFoundation                 0xd5f54 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
13 CoreFoundation                 0xe232c __CFRunLoopDoSource0 + 176
14 CoreFoundation                 0x66210 __CFRunLoopDoSources0 + 244
15 CoreFoundation                 0x7bba8 __CFRunLoopRun + 836
16 CoreFoundation                 0x80ed4 CFRunLoopRunSpecific + 612
17 GraphicsServices               0x1368 GSEventRunModal + 164
18 UIKitCore                      0x3a23d0 -[UIApplication _run] + 888
19 UIKitCore                      0x3a2034 UIApplicationMain + 340
20 app                            0x679c main + 8 (main.m:8)
21 ???                            0x1a5fec960 (Manquant)
EXC_BAD_ACCESS (KERN_INVALID_ADDRESS) 0x0000000000000000
Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x7d44 class_getMethodImplementation + 64
1  Foundation                     0xa35c0 _NSKVONotifyingOriginalClassForIsa + 32
2  Foundation                     0xaaf8 _NSKeyValueObservationInfoGetObservances + 264
3  Foundation                     0x3f6d8 NSKeyValueWillChangeWithPerThreadPendingNotifications + 232
4  WebKit                         0x432fe0 WebKit::PageClientImplCocoa::gpuProcessDidExit() + 44
5  WebKit                         0x65d628 WebKit::WebProcessPool::gpuProcessExited(int, WebKit::ProcessTerminationReason) + 488
6  WebKit                         0x6ea804 WebKit::GPUProcessProxy::gpuProcessExited(WebKit::ProcessTerminationReason) + 216
7  WebKit                         0x6ea97c WebKit::GPUProcessProxy::processIsReadyToExit() + 136
8  WebKit                         0x1d8178 WebKit::GPUProcessProxy::didReceiveMessage(IPC::Connection&, IPC::Decoder&) + 200
9  WebKit                         0x41835c IPC::Connection::dispatchMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder> >) + 260
10 WebKit                         0x41b068 WTF::Detail::CallableWrapper<IPC::Connection::enqueueIncomingMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder> >)::$_13, void>::call() + 188
11 JavaScriptCore                 0x520b0 WTF::RunLoop::performWork() + 200
12 JavaScriptCore                 0x52de8 WTF::RunLoop::performWork(void*) + 36
13 CoreFoundation                 0xd5f24 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
14 CoreFoundation                 0xe22fc __CFRunLoopDoSource0 + 176
15 CoreFoundation                 0x661c0 __CFRunLoopDoSources0 + 244
16 CoreFoundation                 0x7bb7c __CFRunLoopRun + 836
17 CoreFoundation                 0x80eb0 CFRunLoopRunSpecific + 612
18 GraphicsServices               0x1368 GSEventRunModal + 164
19 UIKitCore                      0x3a1668 -[UIApplication _run] + 888
20 UIKitCore                      0x3a12cc UIApplicationMain + 340
21 app                            0x679c main + 8 (main.m:8)
22 ???                            0x1e3b64960 (Manquant)

To Reproduce:

Unfortunately I could not reproduce this. It seems to happen only on iOS 16 although it might just be because of our userbase and the relative rarity of the crash (2% partial rollout of the update).
The logs indicate that the crash happens after a screen unmounts, where there was an html5 video playing via react-native-webview.

Environment:

  • OS: iOS
  • OS version: iOS 16
  • react-native version: 0.71.11
  • react-native-webview version: 13.2.1
@Minishlink
Copy link
Author

10% rollout and still only iOS 16

This could come from an observer not correctly deallocated ?

Maybe the memory leak from #2930
If not one of #2535 #2686

I'll send an update with #2930 reverted and will keep you updated

@francesco-cerio
Copy link

Hi, I'm having the same crash.
Any update on this?

@Minishlink
Copy link
Author

Minishlink commented Jul 4, 2023

I reverted #2930 and deployed an update of our app, it is at 2% partial rollout and so far no crash. On Thursday (10% rollout), I will confirm this. (EDIT on Thursday : confirmed)

diff --git a/node_modules/react-native-webview/apple/RNCWebViewImpl.m b/node_modules/react-native-webview/apple/RNCWebViewImpl.m
index ffcf4b2..6b5a8de 100644
--- a/node_modules/react-native-webview/apple/RNCWebViewImpl.m
+++ b/node_modules/react-native-webview/apple/RNCWebViewImpl.m
@@ -436,16 +436,9 @@ - (WKWebViewConfiguration *)setUpWkWebViewConfig
   return wkWebViewConfig;
 }
 
-// react-native-mac os does not support didMoveToSuperView https://github.com/microsoft/react-native-macos/blob/main/React/Base/RCTUIKit.h#L388
-#if !TARGET_OS_OSX
-- (void)didMoveToSuperview
-{
-  if (_webView == nil) {
-#else
 - (void)didMoveToWindow
 {
   if (self.window != nil && _webView == nil) {
-#endif // !TARGET_OS_OSX
     WKWebViewConfiguration *wkWebViewConfig = [self setUpWkWebViewConfig];
     _webView = [[RNCWKWebView alloc] initWithFrame:self.bounds configuration: wkWebViewConfig];
     [self setBackgroundColor: _savedBackgroundColor];

@minotogna
Copy link

I reverted #2930 and deployed an update of our app, it is at 2% partial rollout and so far no crash. On Thursday (10% rollout), I will confirm this.

diff --git a/node_modules/react-native-webview/apple/RNCWebViewImpl.m b/node_modules/react-native-webview/apple/RNCWebViewImpl.m
index ffcf4b2..6b5a8de 100644
--- a/node_modules/react-native-webview/apple/RNCWebViewImpl.m
+++ b/node_modules/react-native-webview/apple/RNCWebViewImpl.m
@@ -436,16 +436,9 @@ - (WKWebViewConfiguration *)setUpWkWebViewConfig
   return wkWebViewConfig;
 }
 
-// react-native-mac os does not support didMoveToSuperView https://github.com/microsoft/react-native-macos/blob/main/React/Base/RCTUIKit.h#L388
-#if !TARGET_OS_OSX
-- (void)didMoveToSuperview
-{
-  if (_webView == nil) {
-#else
 - (void)didMoveToWindow
 {
   if (self.window != nil && _webView == nil) {
-#endif // !TARGET_OS_OSX
     WKWebViewConfiguration *wkWebViewConfig = [self setUpWkWebViewConfig];
     _webView = [[RNCWKWebView alloc] initWithFrame:self.bounds configuration: wkWebViewConfig];
     [self setBackgroundColor: _savedBackgroundColor];

@Minishlink that pr I guess fixed another bug... is it safe to revert it?

@Minishlink
Copy link
Author

Basically, before this PR, ios webviews were rendered only when the current windows was completely focused, and not during focus. Eg. on a tab view, it was not visible while swiping the tab. If you need this behavior and it is more important that the crashes then yes, don't revert it.

@minotogna
Copy link

Basically, before this PR, ios webviews were rendered only when the current windows was completely focused, and not during focus. Eg. on a tab view, it was not visible while swiping the tab. If you need this behavior and it is more important that the crashes then yes, don't revert it.

@Minishlink got it. thank you. I don't need that behaviour . we'll try to revert to version 12.4.0 waiting for the official fix.

@ororsatti
Copy link

ororsatti commented Jul 15, 2023

It might be related to the memory leak RNWW
introduced on 13.0.0 .
#3020

@Minishlink
Copy link
Author

#2930 has been reverted in #3041, issue is fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants