mbdavid/LiteDB

[QUESTION] LiteDB almost works perfectly with Uno on WebAssembly but loses things on close

Rippletank opened this issue · 1 comments

I have an app using Uno platform on WebAssembly which appears at first to work fine with LiteDB to store data locally. However, deeper testing shows that not all updates are reliably saved and reopening the app reverts to a previous states or sometimes loses everything.

Is there anything I can do to ensure all changes are flushed properly on exit? I have tried CheckPoint on the db but this doesn't improve the situation. I also tried manually creating the filestreams (data and log) and calling flush on page close but the database is still sometimes lost completely on restart.

I naively didn't think about LiteDB at first and it actually appeared to work fine. It looks like Uno builds some kind of virtual file system which streams to IndexDB.

As a background, this was an existing app just being converted from Xamarin to Maui. As the app is almost completely SkiaSharp based I was able to try it on Uno, too, to get the WASM version. LiteDB provides cache and offline operation which was important.

Also, worth noting, the app uses multiple threads even in WASM but the problem happens with single threads, too.

Not sure if it will work, but perhaps setting a lock(object) or similarly a bool isBusy in the language prior to db writes, and then clear / set false after completed. On close, if object is locked or isBusy, wait (indefinitely or for an acceptable timeout period if you keep the writes minimal).