Release realm in autoreleasepool.
Released realm.
Fatal Exception: std::__1::system_error
mutex lock failed: Invalid argument
Crashed: com.google.firebase.crashlytics.ios.exception
0 pitt 0x102fff184 FIRCLSProcessRecordAllThreads + 392 (FIRCLSProcess.c:392)
1 pitt 0x102fff568 FIRCLSProcessRecordAllThreads + 423 (FIRCLSProcess.c:423)
2 pitt 0x102ff5de4 FIRCLSHandler + 34 (FIRCLSHandler.m:34)
3 pitt 0x102ff1ae4 __FIRCLSExceptionRecord_block_invoke + 218 (FIRCLSException.mm:218)
4 libdispatch.dylib 0x1b958b524 _dispatch_client_callout + 16
5 libdispatch.dylib 0x1b953e0b0 _dispatch_lane_barrier_sync_invoke_and_complete + 56
6 pitt 0x102ff127c FIRCLSExceptionRecord + 225 (FIRCLSException.mm:225)
7 pitt 0x102ff0f1c FIRCLSTerminateHandler() + 285 (FIRCLSException.mm:285)
8 libc++abi.dylib 0x1b968e14c std::__terminate(void (*)()) + 16
9 libc++abi.dylib 0x1b968e0e4 std::terminate() + 44
10 Realm 0x104a2b36c std::__1::shared_ptr<realm::_impl::CollectionNotifier> std::__1::atomic_load<realm::_impl::CollectionNotifier>(std::__1::shared_ptr<realm::_impl::CollectionNotifier> const*) + 5427 (memory:5427)
11 Realm 0x104c84ddc realm::Group::~Group() + 122
12 Realm 0x104c8f25c realm::Transaction::close() + 60
13 Realm 0x104c91d34 TransactionDeleter(realm::Transaction*) + 20
14 Realm 0x104c969a8 std::__1::__shared_ptr_pointer<realm::Transaction*, void (*)(realm::Transaction*), std::__1::allocator<realm::Transaction> >::__on_zero_shared() + 13896
15 Realm 0x104a2b484 std::__1::shared_ptr<realm::_impl::CollectionNotifier>::~shared_ptr() + 3586 (memory:3586)
16 Realm 0x104b3a514 realm::Realm::~Realm() + 81 (shared_realm.cpp:81)
17 Realm 0x104a2b484 std::__1::shared_ptr<realm::_impl::CollectionNotifier>::~shared_ptr() + 3586 (memory:3586)
18 libobjc.A.dylib 0x1b95e6c90 object_cxxDestructFromClass(objc_object*, objc_class*) + 112
19 libobjc.A.dylib 0x1b95facc4 objc_destructInstance + 88
20 libobjc.A.dylib 0x1b960173c _objc_rootDealloc + 52
21 Realm 0x104b0b890 -[RLMRealm dealloc] + 814 (RLMRealm.mm:814)
22 libobjc.A.dylib 0x1b960404c AutoreleasePoolPage::releaseUntil(objc_object**) + 180
23 libobjc.A.dylib 0x1b9603f44 objc_autoreleasePoolPop + 224
24 libswiftObjectiveC.dylib 0x1efff2bd8 autoreleasepool<A>(invoking:) + 68
25 pitt 0x102f1a8c4 partial apply for closure #1 in PageCacheService.delete(in:) + 584 (PageCacheService.swift:584)
26 pitt 0x102f353f4 thunk for @escaping @callee_guaranteed () -> () + 4376204276 (<compiler-generated>:4376204276)
27 libdispatch.dylib 0x1b958a9a8 _dispatch_call_block_and_release + 24
28 libdispatch.dylib 0x1b958b524 _dispatch_client_callout + 16
29 libdispatch.dylib 0x1b95378a4 _dispatch_lane_serial_drain$VARIANT$mp + 608
30 libdispatch.dylib 0x1b9538294 _dispatch_lane_invoke$VARIANT$mp + 416
31 libdispatch.dylib 0x1b954178c _dispatch_workloop_worker_thread + 588
32 libsystem_pthread.dylib 0x1b95dcb74 _pthread_wqthread + 272
33 libsystem_pthread.dylib 0x1b95df740 start_wqthread + 8
Use autoreleasepool in DispatchQueue.
public func delete(in controllerIds: [String]) {
guard !controllerIds.isEmpty else { return }
transactionQueue.async {
autoreleasepool{ [weak self] in
let logHelper = LogHelper(subsystem: "PageCacheService", category: "DeleteByControllerId")
do {
logHelper.d("Deleting \(controllerIds)")
let realm = try RealmCacheHelper.shared.realm()
let matrix = self?.list(realm, in: controllerIds)
let state = self?.find(realm, in: controllerIds)
let emptyMatrix = matrix?.isEmpty ?? true
let emptyState = state?.isEmpty ?? true
guard !emptyMatrix || !emptyState else {
logHelper.d("Cache not found \(controllerIds)")
return
}
try realm.write {
if let s = state {
realm.delete(s)
}
if let m = matrix {
realm.delete(m)
}
}
logHelper.d("Deleted \(controllerIds)")
}
catch {
logHelper.e("Failed to delete page cache, error = %@", error: error)
Crashlytics.crashlytics().record(error: error)
}
}
}
}
Realm framework version: 5.3.2
Realm Object Server version: N/A
Xcode version: 11.6
iOS/OSX version: 10, 12, 13, 14
Dependency manager + version: CocoaPods 1.8.3
got same error in v5.3.4
Any update on this issue?
It crashed my app 1200 times a week.
Should we remove autoreleasepool?
Same on v5.4.4.
Is there any workaround?
Hi @KimiChiu , unfortunately I cannot reproduce the issue.
Probably a problem could be hidden in one of the calls here. I'd appreciate if you could share the code.
let realm = try RealmCacheHelper.shared.realm()
let matrix = self?.list(realm, in: controllerIds)
let state = self?.find(realm, in: controllerIds)
Also to strongify weak self could be a good idea as ('partial apply for closure' in the stack trace saying the weak self could be released)
I thought the problem was from here.
21 Realm 0x104b0b890 -[RLMRealm dealloc] + 814 (RLMRealm.mm:814)
Because there's a 12 Realm 0x104c8f25c realm::Transaction::close() + 60 which seems like it's closing the transaction.
And the whole stack ends here.
10 Realm 0x104a2b36c std::__1::shared_ptr<realm::_impl::CollectionNotifier> std::__1::atomic_load<realm::_impl::CollectionNotifier>(std::__1::shared_ptr<realm::_impl::CollectionNotifier> const*) + 5427 (memory:5427)
Maybe the problem is inside realm deallocation?
This is a convenient method to get another realm instance from a different configuration.
RealmCacheHelper.shared.realm()
func realm() throws -> Realm {
return try Realm(configuration: config)
}
md5-271572887ddf5b7192c3a4cba45ebf27
public func list(_ realm: Realm, in controllerIds: [String]) -> Results<MatrixCache> {
return realm.objects(MATRIX_CLASS).filter("\(MatrixCache.Column.ControllerId.rawValue) IN %@", controllerIds).sorted(byKeyPath: MatrixCache.Column.Page.rawValue, ascending: true)
}
public func find(_ realm: Realm, in controllerIds: [String]) -> Results<StateCache> {
return realm.objects(STATE_CLASS).filter("\(StateCache.Column.ControllerId.rawValue) IN %@", controllerIds)
}
I can't reproduce it either.
Hi @KimiChiu
We've released a major update for Realm. I would appreciate if you could try a latest version 10.1.2
Good news! I'll let you know if the problem still exists.
I'll close this issue due to inactivity. If the you still see the same issue please comment and we can re-open it.
@pavel-ship-it I just opened a new issue similar to this one 馃槵
@rogerluan Is there a link to your issue?
I released a new version to TestFlight with the latest realm two weeks ago and it's working well.
I'll submit for App Store review today to see if the problem was resolved.
It's just above my comment: https://github.com/realm/realm-cocoa/issues/6966
But it was an issue on my end, happening only during unit tests.
The problem is still there.
I just opened a new issue #6993.
It's now happening when I try to insert new data into table.
And there's another error report which is similar to this one.