Skip to content

getDocPresence returns another doc's presence when their channels collide #759

Description

@alecgibson

Summary

Connection.getDocPresence caches presence by channel, and a doc's channel is collection + '.' + id. Docs whose names contain dots can share a channel, so the second caller silently gets the first doc's instance:

connection.getDocPresence('notes', 'private.alice');
connection.getDocPresence('notes.private', 'alice'); // collection 'notes', id 'private.alice'

Local presence created on the second one is sent for notes/private.alice, and transformed against that doc's ops. The same cache means getDocPresence after getPresence on the same channel string returns the untyped Presence, and vice versa.

With #752, a DocPresence ignores presence for any other doc, so nothing crosses between the two docs over the wire. But the two docs still can't both have presence on one connection.

Suggested fix

The cache, message dispatch (Connection._handlePresence looks up _presences[message.ch]) and server-side presence subscriptions are all keyed by channel, so two docs sharing a channel can't be told apart without an unambiguous channel name, such as escaping dots in DocPresence.channel.

Every client and server builds that same string, though, and since #752 the server rejects doc presence whose channel doesn't match it. So any change to the channel format has to be accepted in both formats on the server, depending on the client's protocol version (agent.protocol), so that mixed-version clients keep working.

A cheaper first step: make getDocPresence throw when the cached instance isn't a DocPresence for the requested doc, rather than silently returning it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions