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: sync state with disconnected peers (take 2) #891

Merged
merged 3 commits into from
Oct 4, 2024

Conversation

gmaclennan
Copy link
Member

@gmaclennan gmaclennan commented Oct 3, 2024

There are two scenarios where a disconnected peer results in sync never showing as complete.

Scenario A:

  1. 3 or more peers are connected.
  2. A peer disconnects (e.g. wifi off)
  3. Remaining peers add data (including inviting another device)
  4. Any peer that was previously connected to the peer that disconnected thinks that the disconnected peer still "wants" data, so sync never completes.

Scenario B:

  1. 3 or more peers are connected
  2. A peer adds some data that is not synced (e.g. adds an observation while sync is not enabled)
  3. That peer disconnects
  4. Remaining peers attempt to sync.
  5. Sync never completes because peers are waiting for data from disconnected peer.

Note that these bugs affect project.$sync.waitForSync(), which I don't think the front-end is not currently using. The mechanism used for determining if sync is completed in the front-end may still work.

Fix

This PR fixes what appears to be an oversight for what happens when a peer disconnects (e.g. turns wifi off or force-closes app). We were removing the PeerSyncController, but we were not removing the remote state from CoreSyncState. I think I had some confusion about whether we should keep remote states for disconnected peers. For now, this PR "fixes" this to just completely remove remote states for disconnected peers. If we think keeping the remote state for disconnected peers in the future is useful, we can add it at a later stage. Right now, the remote state for a disconnected peer is just a cause of bugs, so not useful.

@gmaclennan gmaclennan self-assigned this Oct 3, 2024
@gmaclennan gmaclennan marked this pull request as draft October 3, 2024 15:24
@gmaclennan gmaclennan marked this pull request as ready for review October 3, 2024 15:59
@gmaclennan gmaclennan requested a review from EvanHahn October 3, 2024 16:04
/**
* @param {PeerId} peerId
*/
#getOrCreatePeerState(peerId) {
Copy link
Member Author

Choose a reason for hiding this comment

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

The name of this method was misleading, and its use in #onPeerRemove was causing a bug, because it was recreating a removed state.

src/sync/sync-api.js Outdated Show resolved Hide resolved
/**
* @param {string} peerId
*/
disconnectPeer(peerId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: should this be called removePeer() to match addPeer()? Same comment applies elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

I renamed it because there is a removePeer in CoreSyncState which means something different.

@gmaclennan gmaclennan merged commit 301a082 into main Oct 4, 2024
6 checks passed
@gmaclennan gmaclennan deleted the fix/sync-state-disconnected-peers-v2 branch October 4, 2024 08:44
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.

2 participants