Dexie.js icon indicating copy to clipboard operation
Dexie.js copied to clipboard

Unidentified issues / app hangs after upgrading Dexie to v4

Open duncannz opened this issue 1 year ago • 1 comments

Firstly thanks for an awesome library!

After releasing a new version of our Electron app, we started receiving reports of the app hanging when using critical UI components that involved querying using Dexie, as well as, strangely enough, bugs that were symptomatic of Firestore documents not loading (Firestore uses a client-side SDK for setting up listeners on documents in the database).

We didn't manage to reproduce the issues ourselves, and there were no console logs or any other clues as to what was going on for affected users. After combing through the changes in the affected version of our Electron app, the only change that seemed plausibly involved was upgrading Dexie from 3.2.6 to 4.0.1 (the only dependency change), so we released another version in which the only change was to roll Dexie back to 3.x (3.2.7), and the user reports of these issues completely stopped.

Unfortunately, I don't have any ideas as to what was causing the issues or how to diagnose them further, and we wouldn't be in a position to try releasing an update that could potentially reintroduce the issues for diagnostic purposes. I know this doesn't provide enough information to investigate further and I don't expect this issue to remain open, but I am posting it as I would be very interested to hear if anyone else has experienced anything similar, and also think it would be helpful for anyone currently troubleshooting similar issues to see our experience.

duncannz avatar Apr 19 '24 10:04 duncannz

Thanks for the report.

My speculation: One change in dexie@4 is the introduction of a cache used by live-queries only, that allows to reply to liveQueries directly from memory. In case a component has some effect hooks that for some reason trigger an infinite re-render, this could potentially do that much faster (without async waits for indexeddb) with the cache than without it and this could potentially get into a situation where it's consuming all CPU - while without the cache (in dexie 3), it would have left some breath for other tasks while querying indexeddb and not manifest itself the same way.

The cache in dexie@4 can be disabled by providing the option {cache: 'disabled'} to Dexie constructor:

const db = new Dexie("dbname", { cache: 'disabled});

If anyone else would experience this issue, please try whether { cache: 'disabled' } would solve it.

I think that we probably should build a trap into Dexie that stops these possible loops from happening so that a dev could fix the looping code if it happens - we could for example detect if extremely many re-queries happens during a second and then throw an error.

dfahlander avatar Apr 19 '24 10:04 dfahlander