Skip to content

🐛 Bug Report: Closing one realtime connection deletes the user's presence while another connection is still open #14342

Closed

Description

@JoshiJoshiJoshi

👟 Reproduction steps

  1. Self-hosted Appwrite 2.4.0 with realtime. User A is signed in in two places (two tabs, or phone and desktop), i.e. two realtime connections.
  2. An observer subscribes to the presences channel.
  3. Connection 1 calls realtime.upsertPresence({ status: 'online-1', ... }), then connection 2 calls realtime.upsertPresence({ status: 'online-2', ... }). Both get the same presence ID (one record per user).
  4. Close connection 1 (close the tab).

👍 Expected behavior

User A is still connected through connection 2, so the presence stays, or at least is not deleted while another connection of the same user still holds it.

👎 Actual Behavior

The presence record is deleted and the observer receives presences.*.delete, although connection 2 is still open. User A shows as offline until connection 2 upserts again (which creates a new record with a new ID). Reproduced 2 of 2 runs, connections on the same and on different realtime nodes.

Related: a second upsertPresence with a different presenceId on the same user silently updates the existing record and returns the existing ID; the requested ID never exists (GET → 404). This is consistent with "one presence per user", but it is not reported to the client.

Cause: Presences\State::upsertForUser() keeps one row per userInternalId, while every connection that upserted remembers the ID in its own connections[...]['presences']. onClose deletes all remembered IDs without checking whether another connection of the same user still holds them.

🎲 Appwrite version

2.4.0 (same design since presences were introduced in 2.0.0)

💻 Operating system

Linux (Debian 12), Docker

🧱 Your Environment

Self-hosted, Postgres adapter, two API/realtime nodes.

💡 Suggested fix

Track presence ownership per connection (reference count, or a per-connection record), and only delete the user's presence when the last connection holding it closes. Across nodes this needs shared state (e.g. a Redis set of connection IDs per presence) or a per-connection presence row.

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find a similar issue

🏢 Have you read the Code of Conduct?

  • I have read the Code of Conduct

Activity

  1. added
    api / realtime
    product / databases
    product / vcs
    sdk / cli
    on Oct 11, 2026
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

    api / realtimeproduct / databasesproduct / vcssdk / cli

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions