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

Ignore doc does not exist on presence destroy #381

Merged
merged 2 commits into from
Jul 22, 2020
Merged

Conversation

alecgibson
Copy link
Collaborator

When we destroy local presence, we attempt to update the presence to
null for remote clients as part of the cleanup.

However, if we delete a doc, and then destroy the associated presence,
the presence attempts to send a message on a deleted doc, which returns
an error.

Let's just ignore this error. There's no need to reset presence on a
deleted doc, because remote clients will already assume it's null.

When we destroy local presence, we attempt to update the presence to
`null` for remote clients as part of the cleanup.

However, if we delete a doc, and then destroy the associated presence,
the presence attempts to send a message on a deleted doc, which returns
an error.

Let's just ignore this error. There's no need to reset presence on a
deleted doc, because remote clients will [already assume it's `null`][1].

[1]: https://github.com/share/sharedb/blob/a81e2c99af77da12885f0fa860e87cc2602a6cc1/lib/client/presence/local-doc-presence.js#L90-L96
@coveralls
Copy link

coveralls commented Jul 20, 2020

Coverage Status

Coverage increased (+0.0008%) to 97.357% when pulling 37d35f0 on presence-destroy into a81e2c9 on master.

Copy link
Contributor

@curran curran left a comment

Choose a reason for hiding this comment

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

LGTM

LocalPresence.prototype.destroy.call(this, function(error) {
// If the doc does not exist, let's just ignore the error. There's no need to
// tidy up presence on a deleted doc.
if (error && error.code === ERROR_CODE.ERR_DOC_DOES_NOT_EXIST) error = null;
Copy link
Contributor

@ericyhwang ericyhwang Jul 22, 2020

Choose a reason for hiding this comment

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

As discussed, doing the skip here means that if !this._doc.type (the check in LocalDocPresence.prototype.submit), the LocalPresence.prototype.destroy.call could have been replaced with a short-circuit.

But you said that you wanted the cleanup here to still run:

delete presence.presence.localPresences[presence.presenceId];

So the update to instead not emit an error in LocalDocPresence.prototype.submit if the value is null seems good. Or short circuit.

This change amends the `destroy` logic for `LocalDocPresence`, which
handled the error in the wrong place, and meant that the `LocalPresence`
would not correctly tidy up the reference to the destroyed local doc
presence.

This change adds a check to `LocalDocPresence.submit`. If we're
submitting `null` on a deleted doc, we just immediately return, since
the remote client will already assume a `null` presence in this case.
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

4 participants