firebase-ios-sdk icon indicating copy to clipboard operation
firebase-ios-sdk copied to clipboard

FIRESTORE INTERNAL ASSERTION FAILED – Failed to commit transaction xxxxxx. Corruption: not an sstable (bad magic number)

Open DRK1004 opened this issue 7 months ago • 4 comments

Description

We are seeing a fatal crash in our iOS production app when using Firestore. The error points to a corruption issue in Firestore’s internal LevelDB storage layer.

Fatal Exception: NSInternalInconsistencyException FIRESTORE INTERNAL ASSERTION FAILED: Failed to commit transaction: <LevelDbTransaction ExecuteQuery: 0 changes (0 bytes):> Failed: Corruption: not an sstable (bad magic number) (expected status.ok())

# Crashlytics - Stack trace
# Application: com.xxxxxxxxxx
# Platform: apple
# Version: XXXXXXX
# Issue: 2b310d601e1cd930d0fbec3312936e3e
# Session: 55d76a6552544fdaaa44c721a0eed7d2_DNE_0_v2
# Date: Tue May 06 2025 02:46:26 GMT-0500 (Central Daylight Time)

Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x83f20 __exceptionPreprocess
1  libobjc.A.dylib                0x172b8 objc_exception_throw
2  Foundation                     0x6de934 -[NSMutableDictionary(NSMutableDictionary) initWithContentsOfFile:]
3  XXXXXXX                      0x18b5328 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&)
4  XXXXXXX                      0x18b4d74 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&)
5  XXXXXXX                      0x1900210 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*)
6  XXXXXXX                      0x19002a0 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*)
7  XXXXXXX                      0x1932cdc firebase::firestore::local::LevelDbTransaction::Commit()
8  XXXXXXX                      0x19296dc firebase::firestore::local::LevelDbPersistence::RunInternal(absl::lts_20240116::string_view, std::__1::function<void ()>)
9  XXXXXXX                      0x193f4d0 firebase::firestore::local::LocalStore::ExecuteQuery(firebase::firestore::core::Query const&, bool)
10 XXXXXXX                      0x198c5b0 firebase::firestore::core::SyncEngine::InitializeViewAndComputeSnapshot(firebase::firestore::core::Query const&, int, firebase::firestore::nanopb::ByteString)
11 XXXXXXX                      0x198c0d0 firebase::firestore::core::SyncEngine::Listen(firebase::firestore::core::Query, bool)
12 XXXXXXX                      0x18b27b4 firebase::firestore::core::EventManager::AddQueryListener(std::__1::shared_ptr<firebase::firestore::core::QueryListener>)
13 XXXXXXX                      0x18d6c5c std::__1::__function::__func<firebase::firestore::core::FirestoreClient::ListenToQuery(firebase::firestore::core::Query, firebase::firestore::core::ListenOptions, std::__1::shared_ptr<firebase::firestore::core::EventListener<firebase::firestore::core::ViewSnapshot>>&&)::$_11, std::__1::allocator<firebase::firestore::core::FirestoreClient::ListenToQuery(firebase::firestore::core::Query, firebase::firestore::core::ListenOptions, std::__1::shared_ptr<firebase::firestore::core::EventListener<firebase::firestore::core::ViewSnapshot>>&&)::$_11>, void ()>::operator()()
14 XXXXXXX                      0x1879d0c firebase::firestore::util::AsyncQueue::ExecuteBlocking(std::__1::function<void ()> const&)
15 XXXXXXX                      0x199999c firebase::firestore::util::Task::ExecuteAndRelease()
16 libdispatch.dylib              0x3dd4 _dispatch_client_callout
17 libdispatch.dylib              0xb400 _dispatch_lane_serial_drain
18 libdispatch.dylib              0xbf30 _dispatch_lane_invoke
19 libdispatch.dylib              0x16cb4 _dispatch_root_queue_drain_deferred_wlh
20 libdispatch.dylib              0x16528 _dispatch_workloop_worker_thread
21 libsystem_pthread.dylib        0x4934 _pthread_wqthread
22 libsystem_pthread.dylib        0x10cc start_wqthread

Since its happening in production environment, so no clear reproduction steps are available but seems related to disk persistence/levelDB corruption. We have exception handling in our mobile app code but seems its not being caught. We would request following information:

  1. How can we detect and handle this LevelDB corruption gracefully. Does firestore report or throw any error that could be caught?
  2. Are there known causes for this corruption or known fixes in newer SDK versions ?

This issue leads to a fatal crash, affecting user experience. We would appreciate guidance on mitigation or recovery strategies.

Reproducing the issue

Since its happening in production environment, so no clear reproduction steps are available.

Firebase SDK Version

10.25.0

Xcode Version

16.2

Installation Method

Swift Package Manager

Firebase Product(s)

Database

Targeted Platforms

iOS

DRK1004 avatar May 16 '25 17:05 DRK1004

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

google-oss-bot avatar May 16 '25 17:05 google-oss-bot

Thanks for reporting, @DRK1004. This error might indicate some sort of disk corruption. I'm not sure if updating the SDK to a later version would fix the issue, but usually updating is recommended in order to get the bug fixes and new features.

rizafran avatar May 20 '25 14:05 rizafran

Hey @DRK1004, I'd like to follow up you're still encountering the issue after updating the SDK?

rizafran avatar Jun 06 '25 15:06 rizafran

We have updated the version to the latest and monitoring it, but with previous version we are still getting the same error.

DRK1004 avatar Jun 06 '25 15:06 DRK1004