Skip to content

Async receive middleware can reorder a presence and its own leave #767

Open

Description

@alecgibson

receive middleware runs separately for each message, and nothing makes one message wait for the previous one. If a client sends a presence and then its leave (p: null), and async receive middleware with uneven latency (for example a per-message auth lookup) lets the leave reach Agent._handleMessage first:

  1. The leave is broadcast, and receivers drop the presence.
  2. The older presence arrives, replaces the stored leave, and is broadcast.
  3. Receivers keep it as a ghost until that client unsubscribes or disconnects.

The reverse can also happen: a presence re-created with the same id after its leave is dropped if it overtakes that leave.

This isn't a regression. #751 closes the same reorder for everything after receive middleware (doc version lookup, receivePresence, transform), but the order it uses is the order messages reach _handleMessage. A fix would take that order before receive middleware instead, for example by stamping each message as it arrives in the agent.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions