-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash when setting value to an existing object #5761
Comments
This looks like a corrupt file. |
@finnschiermer unfortunately all reports of this that I can find are submitted by anonymous user(s). So I can't ask them to provide the realm file to me. |
@michalrentka I've been going through the repo and I've found this: extension RealmDbCoordinator: DbCoordinator {
func perform(request: DbRequest) throws {
if !request.needsWrite {
try request.process(in: self.realm)
return
}
if self.realm.isInWriteTransaction {
DDLogError("RealmDbCoordinator: realm already writing \(type(of: request))")
try request.process(in: self.realm)
return
} If all actions are running through a serial queue then at what point would |
@leemaguire I noticed this behaviour a long time ago, when I didn't have all realm requests running on background serial queues. So this was a quick workaround to an issue I didn't know about - realm shouldn't run on concurrent queues. Then I re-read the docs and moved all requests to serial queues. I left this in, just in case. Anyway realm requests can be performed from multiple background serial queues - sync runs in the background while user can make changes, which are written in another background serial queue. But I didn't see that error in logs for a long time, so it's probably safe to say this doesn't happen anymore. If you suspect this could lead to issues, I can be a bit more aggressive and try to crash there, so maybe I'd get some reports from users. |
@michalrentka Sorry but I got confused by your last comment. Is the bug gone or still there? |
@finnschiermer the bug is still there. I was just trying to explain how the piece of code mentioned above was created. I don't think it has anything to do with the reported crash and the |
@leemaguire @finnschiermer I've got an update from the user. He is still able to reproduce the issue and I was able to get the realm file from him. I can't open the file in Realm Studio, so it's most likely corrupted. But the crash report changed a bit and it looks more like #5344 which I reported some time ago. Link to the database: https://mega.nz/file/w1AXAACJ#c0exEdAP4njaGgKRu_pRXaz2Gk-Ii-lwJn6cBiI98tg. The current crash report:
Any idea how the database gets corrupted like this? |
Expected results
App shouldn't crash when setting value to existing object.
Actual Results
App crashes when accessing existing object and setting value to it.
Steps & Code to Reproduce
I can't reproduce this issue myself, but I can see multiple reports of this on TestFlight. The app has a background sync of data from our server. This issue happens when I want to update an existing object with a new version number after the sync. I've seen reports from multiple users which point to this issue in the same part of the app (same database write).
All writes in the app run on background serial queues. All reads (accessed by UI) run on main queue. There can be multiple serial queues writing in background at the same time.
The crash happens here: https://github.com/zotero/zotero-ios/blob/5c27b78a64eba144e67113cd10d1687ff97b920a/Zotero/Controllers/Sync/SyncActions/StoreVersionSyncAction.swift#L27
UpdateVersionsDbRequest
can be found here: https://github.com/zotero/zotero-ios/blob/5c27b78a64eba144e67113cd10d1687ff97b920a/Zotero/Controllers/Database/Requests/UpdateVersionsDbRequest.swift#L25-L67.I have a simple wrapper for accessing Realm found here: https://github.com/zotero/zotero-ios/blob/5c27b78a64eba144e67113cd10d1687ff97b920a/Zotero/Controllers/Database/RealmDbStorage.swift#L92-L99
https://github.com/zotero/zotero-ios/blob/5c27b78a64eba144e67113cd10d1687ff97b920a/Zotero/Controllers/Database/RealmDbStorage.swift#L121-L136
RCustomLibrary
andRGroup
are simple realm objects, both withRVersions: EmbeddedObject
:https://github.com/zotero/zotero-ios/blob/master/Zotero/Models/Database/RCustomLibrary.swift
https://github.com/zotero/zotero-ios/blob/master/Zotero/Models/Database/RGroup.swift
https://github.com/zotero/zotero-ios/blob/master/Zotero/Models/Database/RVersions.swift
To sum it up: the sync process happens in background serial queue. When it's finished for given object type (item, collection, search, ...) it wants to write new
version
value toRVersions
object stored either inRCustomLibrary
orRGroup
, whereRVersions
is anEmbeddedObject
. NewRealm
is opened (in the same background serial queue), new write transaction is started inautoreleasepool
, aRCustomLibrary
orRGroup
object is fetched from database and there is an attempt to write toRVersions
object when the app crashes.Core version
Core version: 12.5.0 (Realm version 10.28.5)
The text was updated successfully, but these errors were encountered: