Product: Couchbase Lite Component: couchbase-lite Issue Link: CBL-6981 Affects Version: 3.2.x Fix Version: 3.2.4
Summary
- A rare but persistent crash in Couchbase Lite Swift (version 3.2.1) was found, primarily when converting a document to a dictionary using Document.toDictionary().
- The issue is traced to Couchbase Lite internals (in weak reference handling) and often involves nested data structures such as arrays or dictionaries within documents.
- This crash can occur even without apparent multi-threaded access or memory pressure and has led to regular, low-volume application crashes in production.
- This issue usually manifests as rare, low-frequency production crashes.
Symptoms
- Crash occurs and the stack trace points to Objective-C runtime and CouchbaseLite Swift internals (e.g., CBLDictionary.mm:42, objc_loadWeakRetained, objc_retain)
- The crash may occur even if the document is not accessed concurrently elsewhere
Triggers
- Accessing a Couchbase Lite document containing arrays or other nested data structures
- Use of toDictionary() on a document, like:
extension Document { func toLegacyDictionary() -> [String: Any] { var mutableDictionary = self.toDictionary() // <--- crash here mutableDictionary["_id"] = id return mutableDictionary } } - Code may not explicitly involve multiple threads
- Occurs under normal operation, not memory pressure
Verification
- Crash logs showing errors around CBLDictionary.mm:42, DictionaryObject.swift : 72, objc_loadWeakRetained, objc_retain, or related CouchbaseLiteSwift/Objective-C bridging code.
For example:
stacktrace Thread 23 crashed 0 libobjc.A.dylib 0x000000019b1f9ce8 objc_loadWeakRetained 1 CouchbaseLiteSwift 0x000000010ae25f3f [CBLDictionary swiftObject] (CBLDictionary.mm : 42) 2 CouchbaseLiteSwift 0x000000010ad85f3f static CouchbaseLiteSwift.DataConverter.convertGETValue(Any?) -> Any? (DataConverter.swift : 38) 3 CouchbaseLiteSwift 0x000000010ad95a27 closure #1 () -> Any? in CouchbaseLiteSwift.ArrayObject.makeIterator() -> Swift.AnyIterator<Any> (ArrayObject.swift : 73) 4 CouchbaseLiteSwift 0x000000010ad957bf CouchbaseLiteSwift.ArrayObject.toArray() -> [Any] (<compiler-generated>) 5 CouchbaseLiteSwift 0x000000010ada529b CouchbaseLiteSwift.Document.toDictionary() -> [Swift.String : Any] (Document.swift : 219) 6 Inspect 0x0000000102e9e247 (extension in Inspect):CouchbaseLiteSwift.Document.toLegacyDictionary() -> [Swift.String : Any] (Document+Extension.swift : 17) 7 Inspect 0x0000000102c9726f generic specialization <Inspect.FDAFacilityMappingDocument> of closure #1 () -> () in (extension in Inspect):CouchbaseLiteSwift.Database.readDocument<A where A: Swift.Decodable>(withID: Swift.String, queue: __C.OS_dispatch_queue, completion: (Swift.Result<A, Swift.Error>) -> ()) -> () (Database+Extension.swift : 13) 8 Inspect 0x0000000102e62e4b reabstraction thunk helper from @escaping @callee_guaranteed () -> () to @escaping @callee_unowned @convention(block) () -> () (<compiler-generated>)
stacktrace Thread 0 crashed 0 libobjc.A.dylib 0x000000018caf1c54 objc_retain 1 CouchbaseLiteSwift 0x000000010ae0c9df CouchbaseLiteSwift.DictionaryObject.toDictionary() -> [Swift.String : Any] (DictionaryObject.swift : 72) 2 CouchbaseLiteSwift 0x000000010ae19687 CouchbaseLiteSwift.ArrayObject.toArray() -> [Any] (DataConverter.swift : 107) 3 CouchbaseLiteSwift 0x000000010ae0cc57 CouchbaseLiteSwift.DictionaryObject.toDictionary() -> [Swift.String : Any] (DictionaryObject.swift : 218) 4 CouchbaseLiteSwift 0x000000010ae0cb6f CouchbaseLiteSwift.DictionaryObject.toDictionary() -> [Swift.String : Any] (DictionaryObject.swift : 216) 5 CouchbaseLiteSwift 0x000000010ae291b3 CouchbaseLiteSwift.Document.toDictionary() -> [Swift.String : Any] (Document.swift : 217) 6 Inspect 0x0000000102ebf3af (extension in Inspect):CouchbaseLiteSwift.Document.toLegacyDictionary() -> [Swift.String : Any] (Document+Extension.swift : 17)
- Confirm the affected environment is using Couchbase Lite less than version 3.2.4
Workarounds
- There is no good workaround worth suggesting: one can limit calls to access arrays, other nested data structures, or toDictionary(); or refactor code to avoid converting documents with nested arrays/dictionaries unless necessary.
- If encountered, we strongly recommend upgrading to Couchbase Lite 3.2.4 or a newer version, where the weak reference handling is fixed.
Comments
0 comments
Article is closed for comments.