-
Type: Bug
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
2 - S (<= 1 week)
-
3595
Goals
Realm 10 to support concurrent connections
Expected Results
Opening and closing multiple connections should not create the crash "cannot access realm that has been closed."
Actual Results
The second connection throws "cannot access realm that has been closed.", it seems to be released prematurely.
Steps to Reproduce
Note that this problem didn't exist in Realm 6.
Our db layer is implemented as async functions, with each opening and closing connections within the function scope.
This error starts appearing after upgrading to Realm 10.
My guess is that Realm 10 caches and reuses the connection instance, and it is being released prematurely due to reference counting errors
You can replicate this with the code attached:
Code Sample
const Realm = require("realm"); const UserSchema = { name: "User", primaryKey: "id", properties: { id: "string", }, }; it("should work", async () => { openConnection(); // Crashes: cannot access realm that has been closed. await openConnection(); }); async function openConnection() { const realm = await Realm.open({ schema: [UserSchema], }); realm.objects("User"); realm.close(); }
Version of Realm and Tooling
- Realm js: 10.2.0
- Node: 15.8.0 React native: 0.63.2 (seems to be Android only)