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

FirebaseDynamicLink crashes due to object deallocation on app launch. #4308

Closed
alan-andrade opened this issue Nov 13, 2019 · 6 comments
Closed
Assignees
Milestone

Comments

@alan-andrade
Copy link
Contributor

alan-andrade commented Nov 13, 2019

Environment

  • Xcode version: 11.2
  • Firebase SDK version: 6.12.0
  • Firebase Component: DynamicDeeplinks
  • Component version: 4.0.5

Problem

We are in the process of creating a shared framework that contains Firebase. When the framework is imported on the new app, the application crashes right away while trying to retrieve pending deeplinks.

Steps to reproduce:

  1. Create a shared framework with firebase in it.
  2. Import it in a new project and configure firestore on th app delegate.
  3. The main application will crash.

There aren't any custom domains on the Info.plist.

Relevant Code:

Snippet from FIRDLJavaScriptExecutor.m

#pragma mark - WKNavigationDelegate

- (void)webView:(WKWebView *)webView
    didFinishNavigation:(null_unspecified WKNavigation *)navigation {
  __weak __typeof__(self) weakSelf = self;

  // Make sure that the javascript was loaded successfully before calling the method.
  [webView evaluateJavaScript:FIRDLTypeofFingerprintJSMethodNameString()
            completionHandler:^(id _Nullable typeofResult, NSError *_Nullable typeError) {
              if (typeError) {
                [weakSelf handleExecutionError:typeError];
                return;
              }
              if ([typeofResult isEqual:@"function"]) {
                [webView
                    evaluateJavaScript:GINFingerprintJSMethodString()
                     completionHandler:^(id _Nullable result, NSError *_Nullable functionError) {
                       if ([result isKindOfClass:[NSString class]]) {
                         [weakSelf handleExecutionResult:result];
                         // ^^^^^^^^ CRASH due to weakSelf being deallocated.
                       } else {
                         [weakSelf handleExecutionError:nil];
                       }
                     }];
              } else {
                [weakSelf handleExecutionError:nil];
              }
            }];
}

Stacktrace

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x54892ed86e80)
    frame #0: 0x00007fff50bad00b libobjc.A.dylib`objc_release + 11
  * frame #1: 0x0000000109d5757f PSI`__55-[FIRDLJavaScriptExecutor webView:didFinishNavigation:]_block_invoke_2(.block_descriptor=0x0000600002839170, result=@"en-US", functionError=0x0000000000000000) at FIRDLJavaScriptExecutor.m:117:26
    frame #2: 0x00007fff2d0dec4d WebKit`WTF::Detail::CallableWrapper<-[WKWebView _evaluateJavaScript:forceUserGesture:completionHandler:]::$_7, void, API::SerializedScriptValue*, bool, WebCore::ExceptionDetails const&, WebKit::CallbackBase::Error>::call(API::SerializedScriptValue*, bool, WebCore::ExceptionDetails const&, WebKit::CallbackBase::Error) + 363
    frame #3: 0x00007fff2d173647 WebKit`WebKit::GenericCallback<API::SerializedScriptValue*, bool, WebCore::ExceptionDetails const&>::performCallbackWithReturnValue(API::SerializedScriptValue*, bool, WebCore::ExceptionDetails const&) + 41
    frame #4: 0x00007fff2d173502 WebKit`WebKit::WebPageProxy::scriptValueCallback(IPC::DataReference const&, bool, WebCore::ExceptionDetails const&, WebKit::CallbackID) + 296
    frame #5: 0x00007fff2d3d43b4 WebKit`void IPC::handleMessage<Messages::WebPageProxy::ScriptValueCallback, WebKit::WebPageProxy, void (WebKit::WebPageProxy::*)(IPC::DataReference const&, bool, WebCore::ExceptionDetails const&, WebKit::CallbackID)>(IPC::Decoder&, WebKit::WebPageProxy*, void (WebKit::WebPageProxy::*)(IPC::DataReference const&, bool, WebCore::ExceptionDetails const&, WebKit::CallbackID)) + 100
    frame #6: 0x00007fff2cf5964e WebKit`IPC::MessageReceiverMap::dispatchMessage(IPC::Connection&, IPC::Decoder&) + 114
    frame #7: 0x00007fff2d1a3ea8 WebKit`WebKit::WebProcessProxy::didReceiveMessage(IPC::Connection&, IPC::Decoder&) + 24
    frame #8: 0x00007fff2cf44cf2 WebKit`IPC::Connection::dispatchMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder> >) + 158
    frame #9: 0x00007fff2cf47a44 WebKit`IPC::Connection::dispatchIncomingMessages() + 408
    frame #10: 0x00007fff26881d74 JavaScriptCore`WTF::RunLoop::performWork() + 228
    frame #11: 0x00007fff26882002 JavaScriptCore`WTF::RunLoop::performWork(void*) + 34
    frame #12: 0x00007fff23bb2221 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    frame #13: 0x00007fff23bb214c CoreFoundation`__CFRunLoopDoSource0 + 76
    frame #14: 0x00007fff23bb1924 CoreFoundation`__CFRunLoopDoSources0 + 180
    frame #15: 0x00007fff23bac62f CoreFoundation`__CFRunLoopRun + 1263
    frame #16: 0x00007fff23babe16 CoreFoundation`CFRunLoopRunSpecific + 438
    frame #17: 0x00007fff38438bb0 GraphicsServices`GSEventRunModal + 65
    frame #18: 0x00007fff4784fb68 UIKitCore`UIApplicationMain + 1621
    frame #19: 0x00000001067a6ce5 mindfulness`main(argc=1, argv=0x00007ffee945cce8) at main.m:20:20
    frame #20: 0x00007fff51a1dc25 libdyld.dylib`start + 1
    frame #21: 0x00007fff51a1dc25 libdyld.dylib`start + 1
(lldb) 

NOTES

We've been able to workaround the issue by adding FirebaseDeepLinkAutomaticRetrievalEnabled to Info.plist

Related: #3945

Thanks !

@google-oss-bot

This comment has been minimized.

@morganchen12
Copy link
Contributor

@dmandar looks like this can be fixed by taking a strong reference to self inside the completion handler.

@kfieldi5
Copy link

Also hitting this issue.

@morganchen12
Copy link
Contributor

Tentatively adding this to the M61 release, which means the fix will hopefully be out by mid-December.

@rzulkoski
Copy link

rzulkoski commented Nov 22, 2019

I'm getting the same crash using DynamicLinks in an iOS App rather than a shared framework. Adding the key FirebaseDeepLinkAutomaticRetrievalEnabled with a value of NO to the Info.plist does seem to fix the issue. I've also noticed that I don't have this issue with the zipped version of 6.13.0, only with the Carthage version.

@paulb777
Copy link
Member

Was merged with #4325 and will be released with 6.14.0

@firebase firebase locked and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.