Skip to content

New presence sync does not discard previous in-flight sync (RTP18a) #2215

@paddybyers

Description

@paddybyers

Spec requirement

RTP18a: "If a new SYNC is initiated while a previous SYNC sequence is in progress, the previous sync should be discarded and the new one should replace it." The residual members set should be reset to the current map contents when a new sync starts mid-flight.

Current behavior

startSync() in presencemap.ts (line ~131-145) has an explicit guard:

if (!this.syncInProgress) {
  this.residualMembers = Utils.copy(map);
  this.setInProgress(true);
}

When called during an in-progress sync, syncInProgress is already true, so residualMembers is NOT reset. This means members from the first sync's residualMembers set persist, and when the second sync completes, endSync() may incorrectly evict members that were present in the second sync sequence but not explicitly seen (because they were already removed from residualMembers during the first sync's processing).

Root cause

The if (!this.syncInProgress) guard in startSync() was likely intended to be idempotent for duplicate START messages, but it also prevents reset when a genuinely new sync sequence begins. The fix would be to always reset residualMembers = Utils.copy(map) regardless of syncInProgress.

UTS test

  • RTP18a - new sync discards previous in-flight sync in test/uts/realtime/unit/presence/presence_sync.test.ts

Found via UTS (Universal Test Specification) compliance testing.

┆Issue is synchronized with this Jira Task by Unito

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working. It's clear that this does need to be fixed.uts-issueIssues raised there there is an apparent discrepancy between this library and the UTS tests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions