Skip to content

refactor(core): move heartbeat/liveness logic into core behind remote… - #768

Open
LiamCarPer wants to merge 1 commit into
Totodore:mainfrom
LiamCarPer:refactor/move-heartbeat-to-core
Open

refactor(core): move heartbeat/liveness logic into core behind remote…#768
LiamCarPer wants to merge 1 commit into
Totodore:mainfrom
LiamCarPer:refactor/move-heartbeat-to-core

Conversation

@LiamCarPer

Copy link
Copy Markdown
Contributor

refactor(core): move heartbeat/liveness logic into core behind remote-adapter feature

Motivation

The postgres and mongodb adapters independently implement the same
heartbeat/liveness logic: the same nodes_liveness: Mutex<Vec<(Uid, Instant)>>
field, the same interval-based heartbeat job, the same
emit_heartbeat/emit_init_heartbeat helpers, the same recv_heartbeat
handler (~130 LOC duplicated verbatim, only the error type differs) and the
same server_count dead-node pruning. This duplication makes maintenance
harder and is contrary to the goal of #727 (share more code between adapters).

Solution

Move the heartbeat/liveness logic into socketioxide-core behind the existing
remote-adapter feature flag:

  • HeartbeatTracker: wraps nodes_liveness + hb_timeout; on_heartbeat
    (update-or-push, returns whether an InitHeartbeat reply is due),
    server_count (prune dead nodes + self), is_alive.
  • HeartbeatSender trait: uid, send_req, with default
    emit_heartbeat, emit_init_heartbeat and recv_heartbeat implementations.
  • heartbeat_loop helper.

Postgres and mongodb now keep only a thin HeartbeatSender impl (their
adapter-specific send_req + uid) plus a HeartbeatTracker field.
No behavior or wire-format change. Redis is unaffected: it has no heartbeat
(liveness is pub/sub subscriber counting via num_serv).

Closes #767

…-adapter feature

Moves the duplicated heartbeat/liveness logic from the postgres and
mongodb adapters into socketioxide-core behind the existing
remote-adapter feature flag.

- HeartbeatTracker: wraps nodes_liveness + hb_timeout; on_heartbeat
  (update-or-push, returns whether an InitHeartbeat reply is due),
  server_count (prune dead nodes + self), is_alive
- HeartbeatSender trait: uid, send_req, with default emit_heartbeat,
  emit_init_heartbeat and recv_heartbeat implementations
- heartbeat_loop helper

Postgres and mongodb now keep only a thin HeartbeatSender impl.
No behavior or wire-format change.

Closes Totodore#767
@codspeed-hq

codspeed-hq Bot commented Jul 31, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 87 untouched benchmarks


Comparing LiamCarPer:refactor/move-heartbeat-to-core (c0b003a) with main (144497d)

Open in CodSpeed

@LiamCarPer

Copy link
Copy Markdown
Contributor Author

Totodore I wanted to say Thanks for the patience, really appreciate you letting me take on this refactor. Happy to iterate on any feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move heartbeat/liveness logic into core behind the remote-adapter feature flag

1 participant