realm-js
realm-js copied to clipboard
Realm hangs the Node process on Linux
Expected Results
It should be possible to add a listener to a collection without hanging the process.
Actual Results
On Linux (at least on some distributions), Realm hangs the entire process during a write operation when a collection listener is created.
Steps to Reproduce
Please see the example code below.
Code Sample
Run node server.js, where server.js is the following:
const Realm = require('realm');
const uuidV4 = require('uuid').v4;
console.log(process.versions);
const TaskSchema = {
name: 'Task',
properties: {
_id: 'string',
name: 'string',
status: 'string',
},
primaryKey: '_id',
};
async function run() {
const realm = await Realm.open({
schema: [TaskSchema],
deleteRealmIfMigrationNeeded: true
});
setInterval(() => {
realm.write(() => {
realm.create('Task', {
_id: uuidV4(),
name: 'Test event',
status: 'Open',
});
});
}, 2000)
realm.addListener('change', () => {
console.log('something changed - if you see this every 2s, it is working fine');
});
const syncTasks = realm.objects('Task');
// COMMENT OUT THE FOLLOWING 3 LINES TO PREVENT THE BUG
syncTasks.addListener((c, task) => {
console.log('collection changed - this hangs!');
});
}
run().catch((err) => console.error(err));
process.stdin.resume();
Version of Realm and Tooling
- Realm JS SDK Version: 10.2.0 (but same with 6.1.7 and 10.1.3)
- Node: 10, 12 and 15 (tested as part of Electron but reproducible with pure Node)
- Client OS & Version: Ubuntu 20.04 (but some of our users reported the problem on other distributions)
I haven't been able to reproduce it (MacOS 10.15.7 / Debian GNU/Linux 10.8). Can you explain in more detail what you mean by "hangs"? I see collection changed - this hangs! every 2 seconds.
Hi @kneth, unfortunately this is not reproducible with all distributions. For example, we see this with Ubuntu 20.04 but not with Ubuntu 16.04 or 18.04, nor with macOS. On Ubuntu 20, we can reproduce it reliably on two different computers. One of our users also reported the issue with Manjaro 21.0 Ornara. Since we are using Realm on an Electron app, it is crucial for us that it works reliably on different distributions.
Here is a video of what I see on Ubuntu 20.04. First I show the problem, by adding the listener to the collection. You can see that the two callbacks should be triggered every second but it soon hangs. This is a minimal example on Node, but when this happens on the renderer process of Electron the entire UI gets frozen, without any console message or exception raised. In the second part of the video, I am commenting out the collection listener and you can see that this prevent the process to stop.
The expected behavior is that the two callbacks are called indefinitely every second.
The line that actually hangs is not the callback itself, bur rather realm.write() (or `realm.beginTransaction()) if a collection listener is there.
https://user-images.githubusercontent.com/2278117/112162189-21c47d00-8bec-11eb-8328-6421f60ffd4a.mp4
I'm seeing this issue on my Arch Linux distro as well. I'll assign this issue to myself.
Thanks for reporting.
Hi @fronck , any update on this? Can you reproduce it reliably and with which version of Realm?
We are not working on it at the moment but we can reproduce it. We hope to return to it soon.