Realm instance closed during background (custom) sync causing "Cannot access realm that has been closed" error on realm.write() #5731
Labels
Encryption:Off
Frequency:Always
O-Community
Repro:Always
SDK-Use:Local
T-Bug
Waiting-For-Reporter
Waiting for more information from the reporter before we can proceed
How frequently does the bug occur?
Always
Description
We have a sync function that syncs our server with Realm, which can take a while. If the user sends the app to the background during this process, the sync continues for a few seconds before the app is suspended. During this time, the Realm instance is closed (i think?),_ causing the realm.write() call to fail and resulting in the "Cannot access realm that has been closed" error.
So i think the realm instance is closed when app goes to background and thats why we get this error.
Sentry is getting spammed by it.
In sentry we see it always happens after event:
Stacktrace & log output
app.lifecycle { state: background } After that: Error: Exception in HostFunction: Cannot access realm that has been closed.
Can you reproduce the bug?
Always
Reproduction Steps
Step 1.
Start the sync passing the realm
Imagine this takes like 5 minutes.
Step 2
Make the app go in background.
After this the realm.write will be triggered.
Step 3
Expect the following error to happen:
Cannot access realm that has been closed.
Version
"realm": "^11.7.0", "@realm/react": "^0.4.3",
What services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
Build environment
Which debugger for React Native: ..
Flipper
Cocoapods version
No response
The text was updated successfully, but these errors were encountered: