You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
🐛 Bug Report: Closing one realtime connection deletes the user's presence while another connection is still open #14342
api / realtimeFixes and upgrades for the Appwrite Realtime API.product / databasesFixes and upgrades for the Appwrite Database.product / vcsFixes and upgrades for the Appwrite VCS.sdk / cliFixes and upgrades for the Appwrite CLI.
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.
An observer subscribes to the presences channel.
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).
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?
api / realtimeFixes and upgrades for the Appwrite Realtime API.product / databasesFixes and upgrades for the Appwrite Database.product / vcsFixes and upgrades for the Appwrite VCS.sdk / cliFixes and upgrades for the Appwrite CLI.
Activity