-
Notifications
You must be signed in to change notification settings - Fork 172
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
Assertion failed: !realm.is_in_transaction() #6659
Comments
Hello, thanks for reporting this. It seems to me that you tried to open a write transaction while there was another write transaction open for the same Realm. Also, @tgoyne do you have some insight here? @Cheezzhead |
We do support mixing async and sync writes, which is one of the major sources of complexity in the feature. |
I've successfully reproduced this. |
Note that the thing I've reproduced involves suspending while in a write transaction, which is not a safe thing to do. If you're using |
So it's hard to show some minimal producable case, because (a) the assertion errors occur at random times and (b) they don't occur in the places where transactions are happening, but rather at moments of retrieval in a view (so on the main actor). Presumably, the assertion failure occurs when async writes are occurring while objects are retrieved simultaneously? Below is some (edited for clarity) code of how the app handles reads and writes.
These async methods aren't normally usable within views (as far as I've tried, although feel free to correct me), so I still use the 'old' versions of these for retrieving objects on the main actor. Which are basically just synchronous versions of the above (using @tgoyne If you want I can give some more code, or other assertion errors if I come across them. |
#6661 definitely fixes this assertion failure, but if you're never using This is probably unrelated, but |
Good to know, am I correct in assuming it won't do any harm at the moment either? I haven't run across frozen object problems in a while but kept this in as a safeguard. I'm currently running into some other errors (EXC_BAD_ACCESS) after trying to clean up the code/adding debug logging. So not sure at the moment if the assertion failures are fixed because of the cleanup or because this new error is happening before the assertion can trigger. I'll make a new issue for the aforementioned error, and can resume testing this after it's fixed. |
SDK and version
SDK : Swift (SPM)
Version: 10.39.1 (RealmDatabase: 13.10.1)
Observations
Crash log / stacktrace
Steps & Code to Reproduce
It's hard to reproduce this error consistently, although I do get this (and other assertion failures) while randomly clicking through the app.
Most of the Realm-related code (specifically writing) has migrated to the new Actor-isolated realm instances, using
asyncWrite(_:)
, however some parts may still use the older method (usually justtry! Realm()
). Concretely, anytime a view requires a realm object, it is retrieved using the old method (on the main actor). Is it possible that this is the cause of the issue?The text was updated successfully, but these errors were encountered: