Skip to content

Publish online again when a broker reconnects - #34

Merged
tuzzmaniandevil merged 1 commit into
devfrom
fix/online-after-reconnect
Oct 9, 2026
Merged

tuzzmaniandevil merged 1 commit into
devfrom
fix/online-after-reconnect

Conversation

@tuzzmaniandevil

Copy link
Copy Markdown
Contributor

After a broker blip the bot read as offline for up to statusInterval (300 s by default) while it was running fine. Found in the round 2 on-air test.

When the link drops, the broker publishes the will (offline). paho's auto-reconnect then restores the connection, but nothing published a new status until the next tick. Long-standing, not from this week's changes.

Fix

connectBroker sets an OnConnect handler that publishes online on every connect after the first (onReconnect). paho calls the handler for the initial connect too, and that one is already published by connectAndRetry / the token refresh, so it is skipped to avoid a double. connectBroker now takes the broker client and context so the handler can publish.

Testing

  • TestOnReconnectSkipsFirstConnect: first connect does nothing, each later one fires.
  • Binary against Mosquitto with the default 300 s interval, fed by a fake KISS modem, broker stopped 10 s mid-run:
    • before: after the broker returned, no online at all (only the offline at shutdown 30 s later);
    • after: reconnected logged and online published right after the reconnect. Startup still publishes exactly one online.
  • Full suite under -race.

When the link drops the broker publishes our will (offline), and paho's
auto-reconnect brought the connection back without a new status, so the
bot read as offline until the next status tick, up to statusInterval
(300 s by default). An OnConnect handler now publishes online on every
connect after the first; the first is still published by the caller.
@tuzzmaniandevil
tuzzmaniandevil merged commit 6f68983 into dev Oct 9, 2026
1 check passed
@tuzzmaniandevil
tuzzmaniandevil deleted the fix/online-after-reconnect branch October 9, 2026 00:53
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