Repository navigation
Description
👟 Reproduction steps
- Self-hosted Appwrite 2.4.0 with realtime. An observer subscribes to
presences. - A client opens a realtime connection and calls
realtime.upsertPresence({ status: 'online', permissions: [...] }). It has no other subscriptions. - The client disappears without any further packet reaching the server (e.g. a phone loses connectivity; simulated by dropping the client's packets on the server host, then killing the client while the drop is active, and removing the drop after 5 minutes).
👍 Expected behavior
The server detects the dead connection within a bounded time (heartbeat / idle timeout / TCP keepalive), runs the normal close path, deletes the presence and sends presences.*.delete, as the docs describe for "while connected" presences.
👎 Actual Behavior
The server-side socket stays ESTABLISHED with no keepalive timer, the presence record stays (GET 200), and no delete event is ever sent. Observed for 29 minutes and still ongoing; reproduced 2 of 2 runs. Because realtime presences get expiresAt = now + 30 days, the user can appear online for up to 30 days, or until the realtime container restarts. A clean close, FIN or a killed process are handled correctly; only silent network loss is affected.
The same orphaning happens when the realtime process dies hard (SIGKILL, OOM kill, crash): after docker kill -s KILL + start of the realtime container, all presences of its connections stayed (GET 200) with no delete event (2 of 2 runs); a graceful docker restart cleans up correctly via onWorkerExit. On startup there is no reconciliation, although every realtime presence stores hostname, which is never used for cleanup.
Cause: neither the WebSocket adapter nor app/realtime.php configures Swoole heartbeat_check_interval / heartbeat_idle_time or TCP keepalive, and the server never pings clients. A connection without subscriptions is never written to, so not even TCP retransmission detects the dead peer.
🎲 Appwrite version
2.4.0 (no heartbeat and no reconciliation 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
Configure a heartbeat/idle timeout in the realtime server (e.g. heartbeat_idle_time slightly above the SDK ping interval) or enable TCP keepalive, so dead connections go through onClose. On startup, delete presences whose hostname belongs to this host (or track connection ownership in Redis), and give realtime presences a short, refreshed expiresAt instead of 30 days.
👀 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
nk0273926 commentedon Oct 12, 2026
I'd like to work on this issue. The root cause appears to be that silent WebSocket disconnections are not detected within a bounded time, and presences are not reconciled after an unexpected Realtime process termination.
I propose configuring an appropriate heartbeat/idle timeout so dead connections trigger the normal close and presence cleanup flow. I'll also investigate startup reconciliation for orphaned presences using their
hostnameor connection ownership metadata, with regression tests covering silent network loss and unexpected Realtime restarts.fix(realtime): reconcile hostname-orphaned presences on boot (CE)
revert(realtime): keep presence expiry at 30 days
fix(realtime): detect dead presence sockets via heartbeat; shorten ex…
HarshMN2345 commentedon Oct 29, 2026
Fixed in #15059: realtime now closes silent sockets and releases the presences a crashed worker was holding. Thanks for reporting it!