Skip to content

send mqtt disconnect on peer shutdown, derive keepalive from lease, add optional presence to mqp2p - #38

Merged
fabracht merged 1 commit into
mainfrom
mqp2p-clean-disconnect-keepalive
Oct 15, 2026
Merged

fabracht merged 1 commit into
mainfrom
mqp2p-clean-disconnect-keepalive

Conversation

@fabracht

Copy link
Copy Markdown
Contributor
  • Peer::shutdown sends MQTT DISCONNECT after deregistering, and dropping a Peer inside a Tokio runtime does too. Before, the mqtt5 client outlived the peer and kept reconnecting under mqp2p-<name>, so a peer that went offline and back online fought its old client for the session.
  • PeerConfig::with_keepalive_secs, defaulting to a third of the lease (5 s for the default 15 s lease) instead of mqtt5's 60 s. The broker drops a silent client after 1.5 keepalives, checked once per keepalive, so a dead link is noticed in 7.5 to 12.5 s instead of the ~115 s measured in the c2-fusion harness.
  • PeerConfig::with_presence (opt-in): follow MQDB's $DB/_presence/# and skip peers whose MQTT client has disconnected until they reconnect. Out-of-order events are ignored by ts, only mqp2p- client ids are tracked, and the table is capped at 4096 entries. The lease remains the backstop.
  • README: liveness section and the ACL grants peers need (readwrite on mqp2p/responses/#, since MQDB 0.8.33 answers only on topics the requester may publish to).

Tests: shutdown and drop each send a clean DISCONNECT (presence event with unexpected: false), and presence hides a departed peer within 5 s despite a 60 s lease and shows it again on return. All three fail without the disconnect; the presence test also fails without with_presence. Unit tests cover presence ordering, the cap, the client-id filter and the keepalive default. Workspace: 240 passed, 0 failed. The mqp2p integration tests need an installed mqdb binary and are not run in CI; they passed 5 times in a row locally against mqdb 0.8.51.

@fabracht
fabracht merged commit dc91a33 into main Oct 15, 2026
6 checks passed
@fabracht
fabracht deleted the mqp2p-clean-disconnect-keepalive branch October 15, 2026 21:39
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.

1 participant