Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use bee's state at diffStream creation time #80

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

HDegroote
Copy link
Contributor

The behaviour of the streams is unintuitive: the resulting stream can include entries not yet present at the time of creating the stream (no snapshot is taken).
A straightforward solution: use snapshots when creating the stream. I think this conforms more to user expectation: when creating a diffStream, I expect the diffStream at the time I asked for it, not the diffStream of some future state of the bee.

Simple example:

    const s1 = db.createDiffStream(1)
    const s2 = db.createDiffStream(1)

    const s1Added = []
    const s2Added = []
    for await (const elem of s1) { s1Added.push(elem) }
    for await (const elem of s2) { s2Added.push(elem) }

    // s2 can contain more elements than s2 in certain cases

See the test for how to trigger the race condition (it's tricky)

This applies to diffStream, readStream and historyStream. Holding off on implementing the fix for readStream and historyStream until sure the proposed solution is good.

@HDegroote
Copy link
Contributor Author

Added a similar partial fix for createReadStream and createHistoryStream, but I'm not sure they are desired. They seem to solve the race condition (without those fixes the corresponding tests fail), but there could be more complications due to the feed.snapshot behaviour.

@HDegroote HDegroote marked this pull request as ready for review January 29, 2023 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant