Skip to content

Presence.subscribe() reports success after the server rejects it #757

Description

@alecgibson

Summary

Presence._handleSubscribe sets subscribed = true even when the server rejects the subscription:

Presence.prototype._handleSubscribe = function(error, seq) {
  if (this.wantSubscribe) this.subscribed = true;

Doc._handleSubscribe, by contrast, returns on error before marking itself subscribed.

Repro

  1. Reject ps in 'receive' middleware
  2. presence.subscribe(cb): cb gets the error, but presence.subscribed is true
  3. presence.subscribe(cb) again: cb is called with no error, and nothing is sent to the server
  4. Reconnect: _resubscribe sends the subscription again, and its rejection is emitted as 'error' on the Presence, which throws if nothing is listening

This also means apps can't reject presence subscriptions in middleware without leaving the client in a broken state. The presence access control docs in #752 recommend filtering in 'sendPresence' for that reason.

Suggested fix

On error, leave subscribed alone and reset wantSubscribe, as Doc does, so a later subscribe() actually retries and a reconnect doesn't re-send a subscription the server already refused.

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