Fixed
Status Update
Comments
zh...@google.com <zh...@google.com>
zh...@google.com <zh...@google.com>
zh...@google.com <zh...@google.com> #2
There are a few more changes to DataStoreImpl's logic which makes a reevaluation necessary.
Now with Yigit's changes, datastore's [cold flow](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:datastore/datastore-core/src/commonMain/kotlin/androidx/datastore/core/DataStoreImpl.kt;l=118;drc=777ba8f9a1cdb4ca88263c6785c2708846b16d3f;bpv=0;bpt=0 ) always tries to do a dirty read by [readState](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:datastore/datastore-core/src/commonMain/kotlin/androidx/datastore/core/DataStoreImpl.kt;l=208;drc=777ba8f9a1cdb4ca88263c6785c2708846b16d3f;bpv=0;bpt=0 ) which calls [readAndInitOrPropagateAndThrowFailure](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:datastore/datastore-core/src/commonMain/kotlin/androidx/datastore/core/DataStoreImpl.kt;l=261;drc=777ba8f9a1cdb4ca88263c6785c2708846b16d3f;bpv=0;bpt=0 ) that invokes [readDataOrHandleCorruption](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:datastore/datastore-core/src/commonMain/kotlin/androidx/datastore/core/DataStoreImpl.kt;l=446;drc=777ba8f9a1cdb4ca88263c6785c2708846b16d3f;bpv=0;bpt=0 ) only in InitDataStore's [first run](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:datastore/datastore-core/src/commonMain/kotlin/androidx/datastore/core/DataStoreImpl.kt;l=383-392;drc=777ba8f9a1cdb4ca88263c6785c2708846b16d3f;bpv=0;bpt=0 ). Any following read is triggered by IPC's [listener](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:datastore/datastore-core/src/commonMain/kotlin/androidx/datastore/core/DataStoreImpl.kt;l=80;drc=777ba8f9a1cdb4ca88263c6785c2708846b16d3f;bpv=0;bpt=0 ) which calls [readDataAndUpdateCache](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:datastore/datastore-core/src/commonMain/kotlin/androidx/datastore/core/DataStoreImpl.kt;l=278;drc=777ba8f9a1cdb4ca88263c6785c2708846b16d3f;bpv=0;bpt=0 ) which updates the cache to ReadException returned from [attemptRead](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:datastore/datastore-core/src/commonMain/kotlin/androidx/datastore/core/DataStoreImpl.kt;l=328;drc=777ba8f9a1cdb4ca88263c6785c2708846b16d3f;bpv=0;bpt=0 ).
A ReadException is not automatically handled and stays in cache until a updateData call which revisits [readAndInitOrPropagateAndThrowFailure](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:datastore/datastore-core/src/commonMain/kotlin/androidx/datastore/core/DataStoreImpl.kt;l=238-241;drc=777ba8f9a1cdb4ca88263c6785c2708846b16d3f;bpv=0;bpt=0 ), but it doesn't handle the corruption exception because it's already not the first run. In such case, the `handleUpdate` call proceeds to [transformAndWrite](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:datastore/datastore-core/src/commonMain/kotlin/androidx/datastore/core/DataStoreImpl.kt;l=338-342;drc=777ba8f9a1cdb4ca88263c6785c2708846b16d3f;bpv=0;bpt=0 ) which does not catch the exceptions thrown from [readDataFromFileOrDefault](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:datastore/datastore-core/src/commonMain/kotlin/androidx/datastore/core/DataStoreImpl.kt;l=334;drc=777ba8f9a1cdb4ca88263c6785c2708846b16d3f;bpv=0;bpt=0 ).
yb...@google.com <yb...@google.com> #3
can we create a test failure for this? I'm not fully sure what is going wrong here, it is a bit hard to track w/o a repro case.
zh...@google.com <zh...@google.com> #4
> can we create a test failure for this?
Sure I'm working on the code changes.
In the meantime I think this bug might makes the errors e.g. in b/309382591 harder to recover because it doesn't try to handle the corruption until the app restarts so the DS can readAndInit again (with corruption handler logic).
ap...@google.com <ap...@google.com> #5
Project: platform/frameworks/support
Branch: androidx-main
commit 383a67d0e5a9b35e394b212db35bdee892b167fb
Author: Zhiyuan Wang <zhiyuanwang@google.com>
Date: Wed Feb 21 17:04:40 2024
Add tests to verify that CorruptionException is not properly handled after DataStore's first disk read. If the internal state is [ReadException], it will not recover for the rest of the lifecycle.
Fix in the follow up change.
Bug: 289582516
Test: ./gradlew :datastore:datastore-core:jvmTest
Change-Id: Ie77900b5c2cb8fb8e55d4c40364491dea9250784
M datastore/datastore-core/src/commonTest/kotlin/androidx/datastore/core/SingleProcessDataStoreTest.kt
https://android-review.googlesource.com/2972402
Branch: androidx-main
commit 383a67d0e5a9b35e394b212db35bdee892b167fb
Author: Zhiyuan Wang <zhiyuanwang@google.com>
Date: Wed Feb 21 17:04:40 2024
Add tests to verify that CorruptionException is not properly handled after DataStore's first disk read. If the internal state is [ReadException], it will not recover for the rest of the lifecycle.
Fix in the follow up change.
Bug: 289582516
Test: ./gradlew :datastore:datastore-core:jvmTest
Change-Id: Ie77900b5c2cb8fb8e55d4c40364491dea9250784
M datastore/datastore-core/src/commonTest/kotlin/androidx/datastore/core/SingleProcessDataStoreTest.kt
ap...@google.com <ap...@google.com> #6
Project: platform/frameworks/support
Branch: androidx-main
commit 70085fee2af278bb8c3e45e1acfcf3f4cbb05c5a
Author: Zhiyuan Wang <zhiyuanwang@google.com>
Date: Thu Feb 22 15:08:34 2024
DataStore handles CorruptionException for all reads and writes.
Before this change, DataStore didn't handle the CorruptionException for both the reads and writes after initialization.
Fixes: 289582516
Test: ./gradlew :datastore:datastore-core:jvmTest
Change-Id: Icb07b140017b62a905d3626f82aeb993f636c053
M datastore/datastore-core/src/commonMain/kotlin/androidx/datastore/core/DataStoreImpl.kt
M datastore/datastore-core/src/commonTest/kotlin/androidx/datastore/core/SingleProcessDataStoreTest.kt
https://android-review.googlesource.com/2974198
Branch: androidx-main
commit 70085fee2af278bb8c3e45e1acfcf3f4cbb05c5a
Author: Zhiyuan Wang <zhiyuanwang@google.com>
Date: Thu Feb 22 15:08:34 2024
DataStore handles CorruptionException for all reads and writes.
Before this change, DataStore didn't handle the CorruptionException for both the reads and writes after initialization.
Fixes: 289582516
Test: ./gradlew :datastore:datastore-core:jvmTest
Change-Id: Icb07b140017b62a905d3626f82aeb993f636c053
M datastore/datastore-core/src/commonMain/kotlin/androidx/datastore/core/DataStoreImpl.kt
M datastore/datastore-core/src/commonTest/kotlin/androidx/datastore/core/SingleProcessDataStoreTest.kt
na...@google.com <na...@google.com> #7
The following release(s) address this bug.It is possible this bug has only been partially addressed:
* `androidx.datastore:datastore-core:1.1.0-beta02`
* `androidx.datastore:datastore-core-android:1.1.0-beta02`
* `androidx.datastore:datastore-core-iosarm64:1.1.0-beta02`
* `androidx.datastore:datastore-core-iossimulatorarm64:1.1.0-beta02`
* `androidx.datastore:datastore-core-iosx64:1.1.0-beta02`
* `androidx.datastore:datastore-core-jvm:1.1.0-beta02`
* `androidx.datastore:datastore-core-linuxx64:1.1.0-beta02`
* `androidx.datastore:datastore-core-macosarm64:1.1.0-beta02`
* `androidx.datastore:datastore-core-macosx64:1.1.0-beta02`
Description
After a few code refactors and bug fixes, DataStoreImpl no longer handles CorruptionException in reads after initialization is successful.
Specifically, is only used in , while calls which calls which simply caches a also calls
readDataOrHandleCorruption
InitDataStore
readState
readDataAndUpdateCache
attemptRead
ReadException
if any exception is thrown from the read;updateCollector
readDataAndUpdateCache
thus doesn't catchCorruptionException
.Create the bug to track the fix.