Realm-js: Realm (sync) crashes Electron on Windows

Created on 27 Jan 2021  路  5Comments  路  Source: realm/realm-js

Goals

We are building an Electron app using Realm Sync.

Actual Results

It seems that enabling sync on a Realm crashes Electron (see below).

  • the crash occurs when the code runs on electron but not when runs on pure node;
  • the crash appears on Windows but not on macOS;
  • the crash does not appear if no sync option is provided;
  • the problem seems not to appear when the Realm db is already available on disk (i.e., running the code with node first, then with electron).

Steps to Reproduce

On Windows:

> cross-env ELECTRON_ENABLE_LOGGING=true ELECTRON_ENABLE_STACK_DUMPING=true electron .\server.js

will print

{
  node: '14.15.1',
  v8: '8.9.100-electron.0',
  uv: '1.40.0',
  zlib: '1.2.11',
  brotli: '1.0.9',
  ares: '1.16.1',
  modules: '87',
  nghttp2: '1.41.0',
  napi: '7',
  llhttp: '2.1.3',
  openssl: '1.1.1',
  icu: '68.1',
  unicode: '13.0',
  electron: '12.0.0-beta.18',
  chrome: '89.0.4348.1'
}
Logged in with the user id: 601191a37c8bd7628256e19b
Connection[1]: Session[1]: client_reset_config = false, Realm exists = true, async open = false, client reset = false
Connection[1]: Connected to endpoint '52.49.130.120:443' (from '127.0.0.1:51575')
Connection[1]: Verifying server SSL certificate using 155 root certificates
Received fatal exception 0xc06d007f
Backtrace:
        RaiseException [0x00007FFF9B5E3B29+69]
        (No symbol) [0x00007FFF0ABA8E67]

Instead,

> node ./server.js

produces the expected result:

{
  node: '14.15.1',
  v8: '8.4.371.19-node.17',
  uv: '1.40.0',
  zlib: '1.2.11',
  brotli: '1.0.9',
  ares: '1.16.1',
  modules: '83',
  nghttp2: '1.41.0',
  napi: '7',
  llhttp: '2.1.3',
  openssl: '1.1.1g',
  cldr: '37.0',
  icu: '67.1',
  tz: '2020a',
  unicode: '13.0'
}
Logged in with the user id: 601191a37c8bd7628256e19b
Connection[1]: Session[1]: client_reset_config = false, Realm exists = true, async open = false, client reset = false
Connection[1]: Connected to endpoint '52.49.130.120:443' (from '127.0.0.1:51666')
Connection[1]: Verifying server SSL certificate using 155 root certificates
[
  {
    _id: '3d785166-4da9-453a-9e35-cbaec902904b',
    _partition: null,
    name: 'Test event',
    status: 'Open'
  },
  ...
]

Note: the problem does not appear if first the script is run with node, and then with electron. In other words, it seems to crash only if the realm database needs to be created from scratch.

Code Sample

server.js

const Realm = require('realm');
const uuidV4 = require('uuid').v4;

console.log(process.versions);

const TaskSchema = {
  name: 'Task',
  properties: {
    _id: 'string',
    _partition: 'string?',
    name: 'string',
    status: 'string',
  },
  primaryKey: '_id',
};

const app = new Realm.App({ id: 'some-realm-id' });
async function handleLogin() {
  const credentials = Realm.Credentials.anonymous();
  const user = await app.logIn(credentials);
  await user.refreshCustomData();
  console.log(`Logged in with the user id: ${user.id}`);

  const realm = await Realm.open({
    schema: [TaskSchema],
    // inMemory: true,
    sync: {
      user: app.currentUser,
      partitionValue: 'myPartition',
    },
  });

  realm.write(() => {
    realm.create('Task', {
      _id: uuidV4(),
      name: 'Test event',
      status: 'Open',
    });
  });

  const syncTasks = realm.objects('Task');
  console.log(syncTasks.toJSON());
  realm.addListener('change', () => {
    console.log('sync tasks - ', syncTasks.toJSON());
  });
}

handleLogin().catch((err) => console.error(err));
process.stdin.resume();

process.on('uncaughtException', (err, origin) => {
  console.log(err);
  console.log(origin);
});

process.on('unhandledRejection', (reason, p) => {
  console.log('Unhandled Rejection at: Promise ', p, ' reason: ', reason);
  // application specific logging, throwing an error, or other logic here
});

process.on('SIGTERM', (signal) => {
  console.log(`Process ${process.pid} received a SIGTERM signal`);
  process.exit(0);
});

process.on('SIGINT', (signal) => {
  console.log(`Process ${process.pid} has been interrupted`);
  process.exit(0);
});


Version of Realm and Tooling

  • Realm JS SDK Version: 10.1.4
  • Node or React Native: Electron 12 / Node 14 (see logs above)
  • Client OS & Version: Windows 10
O-Community T-Bug T-Bug-Crash

All 5 comments

Thanks a lot for the detailed bug report, I'll try to reproduce this.

I've been unsuccessful in reproducing this.

The following are my outputs of running npx electron server.js on a Windows 10 machine with Realm JS at v10.1.4.

Electron 11 (latest)

PS C:\Users\kraen.hansen\Projects\realm-js-issue-3535> npx electron server.js

{
  node: '12.18.3',
  v8: '8.7.220.31-electron.0',
  uv: '1.38.0',
  zlib: '1.2.11',
  brotli: '1.0.7',
  ares: '1.16.0',
  modules: '85',
  nghttp2: '1.41.0',
  napi: '6',
  llhttp: '2.0.4',
  http_parser: '2.9.3',
  openssl: '1.1.1',
  icu: '67.1',
  unicode: '13.0',
  electron: '11.2.1',
  chrome: '87.0.4280.141'
}
Logged in with the user id: 6013fe2d3ff3614ebd228efe
Connection[1]: Session[1]: client_reset_config = false, Realm exists = true, async open = false, client reset = false
Connection[1]: Connected to endpoint '34.241.208.56:443' (from '127.0.0.1:54669')
Connection[1]: Verifying server SSL certificate using 155 root certificates
[
  {
    _id: ObjectId("6013fec285d906e435716b75"),
    _partition: 'myPartition',
    name: 'Test event!',
    status: 'Open'
  },
  {
    _id: ObjectId("6014009875860910eaa0bee2"),
    _partition: 'myPartition',
    name: 'Test event',
    status: 'Open'
  }
]
sync tasks -  [
  {
    _id: ObjectId("6013fec285d906e435716b75"),
    _partition: 'myPartition',
    name: 'Test event!',
    status: 'Open'
  },
  {
    _id: ObjectId("6014009875860910eaa0bee2"),
    _partition: 'myPartition',
    name: 'Test event!!!',
    status: 'Open'
  }
]

The "sync tasks" console.log came after editing the name field of the task (id 6014009875860910eaa0bee2) via MongoDB Compass.

Electron 12.0.0-beta.19 (beta)

{
  node: '14.15.1',
  v8: '8.9.100-electron.0',
  uv: '1.40.0',
  zlib: '1.2.11',
  brotli: '1.0.9',
  ares: '1.16.1',
  modules: '87',
  nghttp2: '1.41.0',
  napi: '7',
  llhttp: '2.1.3',
  openssl: '1.1.1',
  icu: '68.1',
  unicode: '13.0',
  electron: '12.0.0-beta.19',
  chrome: '89.0.4348.1'
}
Logged in with the user id: 6013fe2d3ff3614ebd228efe
Connection[1]: Session[1]: client_reset_config = false, Realm exists = true, async open = false, client reset = false
Connection[1]: Connected to endpoint '52.49.130.120:443' (from '127.0.0.1:54690')
Connection[1]: Verifying server SSL certificate using 155 root certificates
[
  {
    _id: ObjectId("6013fec285d906e435716b75"),
    _partition: 'myPartition',
    name: 'Test event!',
    status: 'Open'
  },
  {
    _id: ObjectId("60140210555bc226350c8596"),
    _partition: 'myPartition',
    name: 'Test event',
    status: 'Open'
  },
  {
    _id: ObjectId("6014009875860910eaa0bee2"),
    _partition: 'myPartition',
    name: 'Test event!!!',
    status: 'Open'
  }
]
sync tasks -  [
  {
    _id: ObjectId("6013fec285d906e435716b75"),
    _partition: 'myPartition',
    name: 'Test event!',
    status: 'Open'
  },
  {
    _id: ObjectId("60140210555bc226350c8596"),
    _partition: 'myPartition',
    name: 'Test event',
    status: 'Open'
  },
  {
    _id: ObjectId("6014009875860910eaa0bee2"),
    _partition: 'myPartition',
    name: 'Test event!!!!',
    status: 'Open'
  }
]

This is weird, I cannot reproduce it anymore either. I have to say that I deleted the remote collection and stopped/restarted the Sync in the meanwhile, but now it seems to work fine so I will close this issue.

Hi, we have a similar issue with Electron 12 and Realm.

C:\Users\bartoszhernas>SET ELECTRON_ENABLE_STACK_DUMPING=true

C:\Users\bartoszhernas>C:\Users\bartoszhernas\AppData\Local\Programs\freeyourmusicrc\FreeYourMusicRC.exe

C:\Users\bartoszhernas>
ReleaseId: 2d7d071b2a3196bde8b7e0436731b89e2646e9fd
15:37:46.541 > Is windows: true
15:37:46.552 > os.release(): 10.0.21286
15:37:46.560 > Is dev: false
Original user agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) FreeYourMusicRC/6.0.0 Chrome/89.0.4389.69 Electron/12.0.0 Safari/537.36
Replaced user agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) FreeYourMusicRC/6.0.0 Chrome/89.0.4389.69 Safari/537.36
15:37:46.728 > Web contents [object Object] created
rendererLocation:  file://C:\Users\bartoszhernas\AppData\Local\Programs\freeyourmusicrc\resources\app.asar\build\index.html?userPath=C%3A%5CUsers%5Cbartoszhernas%5CAppData%5CRoaming%5CFreeYourMusicRC&deviceId=238033c100a4b6ddcc7cbea41a85bccb9fb91f80c302b01f7f296ec8e98e5cc2
Connection[1]: Session[1]: client_reset_config = false, Realm exists = true, async open = false, client reset = false
Connection[1]: Connected to endpoint '34.241.208.56:443' (from '127.0.0.1:53807')
Connection[1]: Verifying server SSL certificate using 155 root certificates
15:37:50.141 > Checking for update
Received fatal exception 0xc06d007f
Backtrace:
        PackageSidFromProductId [0x00007FFDF93DD6A8+205438]
15:37:51.553 > Update for version 6.0.0 is not available (latest version: 6.0.0, downgrade is disallowed).

Some more info about @bartoszhernas issue as I am working with him.

The latest version it works with is Electron 10.4.0.
Any Electron 11.x, 12.x or even beta 13.x crashes the app.

We can see that Electron crashes the moment that Realm is initialised.
If you need, we can provide you executable of exactly the same code built with Electron 10.4.0 (that works) and Electron 12.0.0 which crashes.

The workaround for us is to ship Electron 10.4.0 for Windows users and Electron 12.0.0 for the rest of the platforms (so we can support ARM64 on Apple).

Any suggestions how we can debug the issue would be much appreciated. The only info we have is Backtrace: PackageSidFromProductId

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ashah888 picture ashah888  路  3Comments

fever324 picture fever324  路  4Comments

max-zu picture max-zu  路  3Comments

timanglade picture timanglade  路  3Comments

blagoev picture blagoev  路  3Comments