{{ message }}
Repository navigation
fix(realtime): dead-connection heartbeat + boot reconciliation - #14717
Draft
ArnabChatterjee20k wants to merge 2 commits into
Draft
ArnabChatterjee20k wants to merge 2 commits into
ArnabChatterjee20k wants to merge 2 commits into
Conversation
The CE orphan sweep runs asynchronously while new connections are already
accepted. A reconnect increments the same per-user row in place, which keeps
its $createdAt, so the row still matched lessThan('$createdAt', $since) and was
deleted despite the fresh live hold.
Select candidates by $updatedAt (the field a reuse actually moves) and delete
through State::deleteOrphan, which re-reads under the same forUpdate row lock
the increment takes and bails when $updatedAt >= $since. Whichever grabs the
lock first wins: a mid-sweep reconnect advances $updatedAt and is skipped; a
sweep delete lets the reconnect create a fresh row. A live hold is never lost.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add StateTest coverage for deleteOrphan: a row not touched since boot is deleted, a row updated after $since (reconnected) is preserved, and a missing row is a no-op. The test caught that the guard compared $updatedAt to $since as raw strings. $updatedAt reads back in ISO form (2026-...T...+00:00) while $since is DB format (space-separated), so 'T' > ' ' made the comparison always true and deleteOrphan never deleted anything. Compare them as \DateTime instants. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Split out of #14606 so the per-socket
connectionscounter can land independently. This carries the realtime dead-connection work that was previously merged into #14606 via #14661, plus follow-up fixes.Contents
heartbeat_check_interval=30/heartbeat_idle_time=60closes silently-dead sockets soonClosereleases the hold (🐛 Bug Report: Realtime presences stay "online" for days after a network loss or a realtime crash #14343).presenceLogsrows for this host not written since boot and run them through the normal offline path;State::deleteOrphanre-checks under the row lock so a row reconnected mid-sweep is left alone. Covered byStateTest.hansi flagged (P1) that the hostname-based boot sweep is unsound on multi-replica self-hosted: the presence row is one shared row per user with
hostname= last writer, and presence is upsert-once (no refresh), so a row last written by host A can still have a live hold on host B. When A restarts, the sweep can delete that row and emit offline while B is connected. The$updatedAtguard only protects writes during the sweep, not pre-existing cross-host holds.A single shared row can't carry per-host hold information, so there's no targeted patch — options are to drop the boot sweep (rely on heartbeat +
expiresAt) or add cross-host liveness. Tracking and resolving that here keeps it off the counter PR.🤖 Generated with Claude Code