Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-1075

Realm 10 concurrent connection crash

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None

      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)

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: