Skip to content

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

Closed

Description

@LiamCarPer

Part of #727.

Move the duplicated heartbeat/liveness logic from the postgres and mongodb
adapters into socketioxide_core behind the existing remote-adapter feature
flag, so it can be shared by each adapter.

Current state:

  • socketioxide-postgres and socketioxide-mongodb each define 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.
  • The wire protocol already lives in core: RequestTypeOut/In::Heartbeat (20)
    and InitHeartbeat (21) in crates/socketioxide-core/src/adapter/remote_packet.rs.
  • Redis is unaffected: it has no heartbeat (liveness is pub/sub subscriber
    counting via num_serv).

Proposed shared API (sketch, in core behind remote-adapter):

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

Postgres and mongodb then keep only a thin adapter: a HeartbeatTracker field
plus a small HeartbeatSender impl. No behavior or wire-format change.

Activity

  1. added a commit that references this issue on Jul 31, 2026
    c0b003a
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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions