Repository navigation
Conversation
…obileNativeFoundation#572) Signed-off-by: Divya Jain <divyajain2405@gmail.com>
djain2405
force-pushed
the
fix/issue-572-sot-single-reader
branch
from
October 17, 2026 03:13
a2de5e3 to
8c1c704
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #572
Description
SourceOfTruthWithBarrier.readercollected the per-key barrier withflatMapLatest. Everywrite()moved that barrier fromBlockedtoOpen, which cancelleddelegate.reader(key)and collected it again.That second collection is how a one-shot reader sees the written value. It also restarts a reader that stays open, such as Room, SQLDelight, or
channelFlow.stream(StoreReadRequest.cached(key, refresh = true))therefore collected the Source of Truth once per write. Yigit noted in #572 that this restart was unintentional, and that filtering reads during a write would keep the post-writeFetcherorigin.An active reader now stays subscribed across writes. A value that arrives while the barrier is blocked, or before this collector has observed the reopen, is held and emitted when the barrier opens. A successful write is still tagged
Fetcher. A failed write still emits theWriteExceptionfirst, and the following value staysSourceOfTruth. A reader is collected again only after its flow completes or fails, so one-shot and non-flow readers still re-read after a write. Cancelling the outer collector still cancels the child reader and releases the barrier.write(),delete(), anddeleteAll()are unchanged. There is no public API change, and Store 6 is not part of this fix.Two separate collectors of the same key still mean two reader subscriptions. This only removes the extra collection inside one collector.
Type of Change
Test Plan
Before the production change,
longLivedReaderIsCollectedOnceAcrossWritesAndKeepsFetcherOriginfailed: after two writes the subscription count was 3, expected 1.SourceOfTruthWithBarrierTests.longLivedReaderIsCollectedOnceAcrossWritesAndKeepsFetcherOrigin: achannelFlowreader stays at one subscription across two writes, the reader scope stays active, and the emissions areSourceOfTruth(null),Fetcher("a"),Fetcher("b"). Cancelling the collector sets the reader cancelled and returnsbarrierCount()to 0.SourceOfTruthWithBarrierTests.longLivedReaderIsNotRestartedWhenWriteFails: a failed write stays at one subscription, emitsWriteException, and does not restart the reader.FlowStoreTests.givenLongLivedSourceOfTruthWhenCachedRefreshThenReaderIsCollectedOnce:stream(cached(key, refresh = true))collects the Source of Truth once and emitsLoading(Fetcher)thenData(Fetcher, "from-network").SourceOfTruthWithBarrierTestsstill cover the one-shot re-read, write failure then success, read failure then recovery, and a cancelled writer reopening the barrier.Locally, on JDK 17:
:store:jvmTest,:store:ktlintCheck,:store:apiCheck, and./gradlew clean build koverXmlReport --continue.Checklist:
Before submitting your PR, please review and check all of the following:
Additional Notes:
No changelog entry. Store adds those at release time. The documentation checkbox is open because this does not change the public API or the documented read behavior.