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

[FIRApp appWasConfiguredTwice:usingOptions:] - Default app has already been configured crash - could this be handled more gracefully? #13132

Open
Kaspik opened this issue Jun 14, 2024 · 4 comments

Comments

@Kaspik
Copy link

Kaspik commented Jun 14, 2024

Description

Recently while moving to SceneDelgate on our end we moved FirebaseApp.configure() to a place where it can be called again during app lifecycle (mainly if app is suspended and then comes from background and rebuilds whole stack).

We haven't noticed that during development, but when shipped on AppStore we started getting crashes Default app has already been configured.. This is being called from [FIRApp appWasConfiguredTwice:usingOptions:] which comes through few methods from FirebaseApp.configure().

Is there really any reason why third-party SDK library should be manually throwing fatalError instead of nonFatal or just producing warning and doing nothing in case configuration is happening again even tho app is configured?

As a solution we added check if FirebaseApp.app() == nil - but this (or even more nicely) could be handled right inside the SDK.
There is no reason why Firebase SDK should be crashing the app in these cases.

Reproducing the issue

Call FirebaseApp.configure() twice in the code.

Firebase SDK Version

10.27.0

Xcode Version

15.4

Installation Method

Swift Package Manager

Firebase Product(s)

All

Targeted Platforms

All

Relevant Log Output

Fatal Exception: com.firebase.core
0  CoreFoundation                 0x9e88 __exceptionPreprocess
1  libobjc.A.dylib                0x178d8 objc_exception_throw
2  CoreFoundation                 0xf9c58 __CFDictionaryCreateGeneric
3  ClassDojo                      0x1338048 +[FIRApp appWasConfiguredTwice:usingOptions:] + 212 (FIRApp.m:212)
4  ClassDojo                      0x1337d5c +[FIRApp configureWithName:options:] + 157 (FIRApp.m:157)
5  ClassDojo                      0x1337bfc +[FIRApp configureWithOptions:] + 133 (FIRApp.m:133)
6  ClassDojo                      0x1337b98 +[FIRApp configure] + 125 (FIRApp.m:125)
7  ClassDojo                      0x148da4 specialized static CDFirebase.setupFirebase(shouldSendReport:) + 18 (CDFirebase.swift:18)
8  ClassDojo                      0x3cc3e0 SceneDelegate.finishAppStartSetup() + 373 (SceneDelegate.swift:373)
9  ClassDojo                      0x3cc1c8 closure #1 in SceneDelegate.scene(_:willConnectTo:options:) + 96 (SceneDelegate.swift:96)
10 Combine                        0xb754 Subscribers.Sink.receive(_:)
11 Combine                        0xb0a8 protocol witness for Subscriber.receive(_:) in conformance Subscribers.Sink<A, B>
12 Combine                        0x12904 closure #1 in Publishers.ReceiveOn.Inner.receive(_:)
13 libswiftDispatch.dylib         0xf58 thunk for @escaping @callee_guaranteed () -> ()
14 libdispatch.dylib              0x24b4 _dispatch_call_block_and_release
15 libdispatch.dylib              0x3fdc _dispatch_client_callout
16 libdispatch.dylib              0x127f4 _dispatch_main_queue_drain
17 libdispatch.dylib              0x12444 _dispatch_main_queue_callback_4CF
18 CoreFoundation                 0x9a6f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
19 CoreFoundation                 0x7c058 __CFRunLoopRun
20 CoreFoundation                 0x80ed4 CFRunLoopRunSpecific
21 GraphicsServices               0x1368 GSEventRunModal
22 UIKitCore                      0x3a23d0 -[UIApplication _run]
23 UIKitCore                      0x3a2034 UIApplicationMain
24 libswiftUIKit.dylib            0x35308 UIApplicationMain(_:_:_:_:)
25 ClassDojo                      0x6b8b40 main (AppDelegate.swift)
26 ???                            0x1af678960 (Missing)
@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@ncooke3
Copy link
Member

ncooke3 commented Jun 14, 2024

Hi @Kaspik, thanks for the feedback. Based on the shared trace, Firebase is being configured in SceneDelegate.scene(_:willConnectTo:options:), which may be called multiple times in an app's lifecycle. The recommended approach is to configure Firebase in UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:) . If you don't already implement that API, see this article (https://peterfriese.dev/blog/2020/swiftui-new-app-lifecycle-firebase/) for guidance on implementing for a SwiftUI lifecycle app.

@Kaspik
Copy link
Author

Kaspik commented Jun 14, 2024

I'm aware of that, we used to have it there, we might move it there back again, but callers aka implementation should still not matter really in this case. There is no reason why Firebase shouldn't simply do nothing if already configured instead of crash the clients.

@ncooke3
Copy link
Member

ncooke3 commented Jun 14, 2024

Understood–– I'll leave this issue open for now. Improving the configuration APIs is on our roadmap so this is helpful feedback, thanks!

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

5 participants