Skip to content

Log MQTT packets dropped while a broker is down - #31

Merged
tuzzmaniandevil merged 1 commit into
devfrom
fix/log-mqtt-drops
Oct 8, 2026
Merged

tuzzmaniandevil merged 1 commit into
devfrom
fix/log-mqtt-drops

Conversation

@tuzzmaniandevil

Copy link
Copy Markdown
Contributor

Packets heard while an MQTT broker is down were dropped without a word. They are still dropped (no buffer), but now logged: one warning when a broker starts dropping, and broker publishing again dropped=N when it recovers.

Found during the joint on-air test: MQTT rows ran exactly 1 short of recv, because a packet heard in the half-second before the first connect was dropped silently (behaviour since fa0bc45).

Two silent paths, both now counted in doPublish

  • Not connected yet / nil client: dropped before this PR too, only into an unread counter.
  • Broker lost mid-run: paho's IsConnected() stays true while it auto-reconnects, and a QoS 0 publish then completes its token without being sent or stored. The first version of this fix missed it; running the real binary caught it. Packet rows are now dropped and counted when IsConnectionOpen() is false.
  • QoS 1 status publishes are untouched: paho stores those across a reconnect.

Testing

  • Unit test with a fake client that is down, reconnecting, or up: one warning per outage, the recovery count, and a second warning on a mid-run outage. Mutation-checked: no reset, warning per packet, no recovery line, and reverting the reconnecting check each fail it.
  • Release-style binary against a fake KISS modem feeding a numbered packet every 0.5 s, and a real Mosquitto that starts late, stops mid-run, and returns, with a subscriber capturing rows:
Situation Log Rows missing at the subscriber
Broker not up at start warning, then dropped=27 packets 0-26 (27)
Broker stopped mid-run warning, then dropped=30 packets 52-81 (30)
  • Full suite under -race.

Packets are still not buffered, but a warning now marks when a broker
starts dropping them and the count is logged once publishing resumes.

Two silent paths: a job reaching a nil or never-connected client, and a
QoS 0 publish while paho auto-reconnects, where IsConnected stays true
and paho completes the token without sending or storing it. Drop and
count both in doPublish. QoS 1 status publishes still go to paho, which
stores them across a reconnect.
@tuzzmaniandevil
tuzzmaniandevil merged commit 74e92e8 into dev Oct 8, 2026
1 check passed
@tuzzmaniandevil
tuzzmaniandevil deleted the fix/log-mqtt-drops branch October 8, 2026 23:40
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