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

fix branchStream to restart after box2 decryption #110

Merged
merged 3 commits into from
Nov 18, 2022

Conversation

staltz
Copy link
Member

@staltz staltz commented Nov 15, 2022

Context

I'm working on putting 2b funky recps in ssb-tribes2, and noticed a race condition in the tests.

Problem

There's a race condition between:

  1. Replicate the shard feed that announces (encrypted!) a group feed
  2. Replicate the group/add-member message (on the invitations feed) that allows us to decrypt (1)

Ideally, (2) happens first and then (1), but if (1) happens first we have a problem. Even though ssb-tribes2 will run reindexEncrypted() when it bumps into a group/add-member msg, the branchStream() in ssb-meta-feeds won't know that it has to "restart". It just stays stuck in live mode, and of course there are no "new" messages. We only have old messages that were decrypted.

Solution

This is not an ideal solution, but it works. I have an idea for the ideal case, which would be a new API in ssb-db2 that streams all the messages that were freshly decrypted. We need that not only for this branchStream problem, but in other cases too, like in the ssb-box2 "monitor" that matches DM triangles.

The current solution is to just track indexingActive (because reindexEncrypted() bumps that) and restart the branchStream query when indexingActive goes to zero. The live stream was also converted to old-and-live because that's the only way how we can get the old-but-freshly-decrypted messages, AND still get the live messages.

1st ❌ 2nd ✔️

@arj03
Copy link
Member

arj03 commented Nov 16, 2022

Had a minor comment. Would be better with a solution in db2 so other modules doesn't need to be aware of this as you say. I think this solution is fine for now, lets get this in and improve this along the way. Just create an issue for it in db2 :)

Copy link
Member

@arj03 arj03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-approving this, the changes looks good after the other PR is merged

@staltz staltz marked this pull request as ready for review November 18, 2022 12:35
@staltz staltz merged commit 2deac87 into master Nov 18, 2022
@staltz staltz deleted the race-condition-hidden-feed branch November 18, 2022 12:42
@arj03 arj03 mentioned this pull request Dec 20, 2022
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.

None yet

2 participants