firebase / firebase/firebase-ios-sdk
`[FIRApp appWasConfiguredTwice:usingOptions:] - Default app has already been configured` crash - could this be handled more gracefully?
- Dominant language
- C++
- Stars
- 6.7k
- Forks
- 1.8k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 75
Description
### 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
```shell
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
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)
```
Contributor guide
Research direction
Start with FIRApp.m at appWasConfiguredTwice:usingOptions: and the configureWithName:options: call chain shown in the crash, then reproduce the issue by calling FirebaseApp.configure() twice. Review the related CDFirebase.swift and SceneDelegate.swift call sites; done means repeated configuration no longer causes the reported fatal crash while existing configuration behavior remains covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- objective-c, swift
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100