Status Update
Comments
zh...@google.com <zh...@google.com> #2
Hi, have you configured CorruptionHandler
in your case? This is turned off by default, you'll have to explicitly configure it to make DataStore handle the case automatically.
je...@gmail.com <je...@gmail.com> #3
We have CorruptionHandler implemented, but there is nothing automatic about it, instead of a runtime error we got a corruption event in which we can set the default values again, which is not a solution. We want to clarify that there is a bug in the library that makes files to get corrupted and is not related to a misuse by the client by using SingleProcessDataStore in multiple processes.
el...@google.com <el...@google.com> #4
Hi there, unfortunately this is a longstanding issue we are actively trying to reproduce on our end, but are unable to so far as it happens in production. We have multiple issues open for this same issue, so to consolidate the info on 1 issue tracker, I will be closing this issue "as duplicate".
Description
DataStore Component used: androidx.datastore:datastore-preferences
DataStore Version used: 1.1.1
Devices/Android versions reproduced on:
If this is a bug in the library, we would appreciate if you could attach:
The issue happened in an Android app, that is always in foreground, without the use of multiprocess (service with different PID), using a singleton of DataStore (provided with Hilt) and just one file, the only thing we did is use the normal read and write from multiple CoroutineScopes, not even that many or that continuously (the scope provided to the datastore instance creation was a new instance of
CoroutineScope(SupervisorJob() + Dispatchers.IO + CoroutineExceptionHandler...)
the CoroutineExceptionHandler just log the error)We are using
SingleProcessDataStore
and were considering migrating toMultiProcessDataStore
but it seems it won't solve anything since we only have one service, we are sure that service was not the issue, and has no PID manually assigned.The issue (ommited data in log since is the same -> 11-06 08:30:15.784 1989 1989 E AndroidRuntime:):
Are you going to tackle this any time soon or should be moving to another solution? The corruption handler is just a fallback to default status which implies a data loss.
We can't afford to use any kind of storage that has data corruption, since data loss is not an option for our clients. We are temporarily migrating our DataStore data to Room while we find a better solution, and is really an inconvenience.
In many years of development never had this issue using Shared Preferences, nor with SQLiteOpenHelper or Room, the thing is we are now moving to Kotlin Multiplatform and there is still the need of an easy way to persist data that doesn't need the complexity of a relational database like the Room ORM (entities, daos, migrations, queries and such), we are using both datastore and Room at the same time in our products.