firebase-ios-sdk: FIRESTORE INTERNAL ASSERTION FAILED: Failed to open DB
[REQUIRED] Step 1: Describe your environment
- Xcode version: 11.4.1
- Firebase SDK version: 6.21.0
- Firebase Component: Firestore
- Component version: 6.21.0
- Installation method: CocoaPods
[REQUIRED] Step 2: Describe the problem
My app is crashing with a fatal exception due to Firestore.
I know several of these crashes has been reported before but since they are locked I could not comment on them.
So far this issue is only happening in production but it’s happening in about 1% of all cases (about 2k crashes so far) so it’s a pretty big problem for us now.
Fatal Exception: NSInternalInconsistencyException
FIRESTORE INTERNAL ASSERTION FAILED: Failed to open DB: Internal: Failed to open LevelDB database at /var/mobile/Containers/Data/Application/2211CDC3-4C78-4450-86AE-A1AC24D902BD/Library/Application Support/firestore/__FIRAPP_DEFAULT/eneco-360/main: LevelDB error: IO error: /var/mobile/Containers/Data/Application/2211CDC3-4C78-4450-86AE-A1AC24D902BD/Library/Application Support/firestore/__FIRAPP_DEFAULT/eneco-360/main/LOCK: Operation not permitted (expected created.ok())
Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x1acd22a48 __exceptionPreprocess
1 libobjc.A.dylib 0x1aca49fa4 objc_exception_throw
2 CoreFoundation 0x1acc24e88 +[_CFXNotificationTokenRegistration keyCallbacks]
3 Foundation 0x1ad0a9044 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:]
4 Eneco 0x100581828 firebase::firestore::util::ObjcThrowHandler(firebase::firestore::util::ExceptionType, char const*, char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 59 (exception_apple.mm:59)
5 Eneco 0x1005814dc firebase::firestore::util::Throw(firebase::firestore::util::ExceptionType, char const*, char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 90 (exception.cc:90)
6 Eneco 0x1005cc7d0 firebase::firestore::util::internal::FailAssertion(char const*, char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*) + 42 (hard_assert.cc:42)
7 Eneco 0x1005cc894 firebase::firestore::util::internal::FailAssertion(char const*, char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*) + 49 (hard_assert.cc:49)
8 Eneco 0x1005a1a30 firebase::firestore::core::FirestoreClient::Initialize(firebase::firestore::auth::User const&, firebase::firestore::api::Settings const&) + 177 (firestore_client.cc:177)
9 Eneco 0x100562724 firebase::firestore::util::AsyncQueue::ExecuteBlocking(std::__1::function<void ()> const&) + 957 (atomic:957)
10 Eneco 0x100582854 firebase::firestore::util::internal::DispatchAsync(NSObject<OS_dispatch_queue>*, std::__1::function<void ()>&&)::$_0::__invoke(void*)
11 libdispatch.dylib 0x1ac9ef184 _dispatch_client_callout
12 libdispatch.dylib 0x1ac9cc710 _dispatch_lane_serial_drain$VARIANT$armv81
13 libdispatch.dylib 0x1ac9cd128 _dispatch_lane_invoke$VARIANT$armv81
14 libdispatch.dylib 0x1ac9d643c _dispatch_workloop_worker_thread
15 libsystem_pthread.dylib 0x1aca3eb88 _pthread_wqthread
16 libsystem_pthread.dylib 0x1aca41760 start_wqthread
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 13
- Comments: 47 (11 by maintainers)
This issue happens for me when I run the app in SwiftUI Preview, and then try to launch it. Xcode keeps the app’s process alive - even after the Preview is no longer visible in Xcode. Having those two processes open at the same time leads to this error.
How to fix:
Activity MonitorappIt’s annoying to deal with so if anyone from Firebase team can fix it, that’d be great 😃
Receiving this error too:
It crash on the very beginning, right after the launch screen disappears. Running on the new M1 MacBook Pro, this wasn’t shown on my previous MacBook Pro using the Intel chip. I need to clean the build folder, restart the simulator, sometimes even the system needs to reboot, to run the app on the simulator.
Having the same issue randomly on my M1 macOS project. Using Swift Package manager. Latest versions. Cleared derived data and reset the cache of the package manager. Still not working.
What helped me was to disable persistence. I started having the issue, when I started implementing Unit Tests. I assume, that the Tests created some kind of 2nd instance. Running for now without persistence, and will then figure out how to add it for production, but disable it for Unit Tests.
@ilnur-nazmutdinov-spark As mentioned in previous comments https://github.com/firebase/firebase-ios-sdk/issues/5423#issuecomment-617309806 and https://github.com/firebase/firebase-ios-sdk/issues/5423#issuecomment-617376885, Firestore will crash if persistence is enabled and the file system is locked. The reproduction steps you listed definitely result in Firestore attempting to open its database which the file system is locked. Unfortunately, we don’t have a fix for this, and don’t have any immediate plans to fix it (it’s a complicated issue). Please check the workarounds outlined in those previous comments, or disable persistence if your app doesn’t need it.
@paulb777 I think that’s possible to add a boolean for check if the Firestore db can be opened. Isn’t it? I’m thinking on checking if the user keychain value can be retrieved. In this way, if firebase change the query to set/get this value we don’t need to change a check logic, because the check logic is on your side and we use the boolean to retry it in a time or use no persistent storage.
CC: @unxavi
Thanks in advance
We’ve found a way to reproduce it on iPhone. You will need an iPhone and an Apple Watch.
When iPhone is rebooted you can’t press action buttons on notifications, but you can do it using Apple Watch.
Same on real iOS device…
Can this happen on real devices? if yes, how do I recover from it without asking users to delete/reinstall the app?
In my experience the “background” state reflected in Crashlytics isn’t terribly accurate. If you can observe some crashes in the background then it’s worth starting down the path of trying to figure that out. If, after fixing that there are still non-background crashes going on that would be a follow-up.
Firestore is incompatible with locked filesystems. In the future we’ll make this better by failing cleanly, but that will just push the failure out as an error out to your code–the failure will still be there.
So you have essentially two paths forward:
.applicationSupportDirectory, not.documentsDirectory). This is only valid if your local data is not sensitive.