Skip to content

fix(mqtt): apply broker changes from the database seamlessly - #70

Merged
stakach merged 1 commit into
masterfrom
fix/broker-changes
Oct 27, 2026
Merged

stakach merged 1 commit into
masterfrom
fix/broker-changes

Conversation

@stakach

@stakach stakach commented Oct 27, 2026

Copy link
Copy Markdown
Member

Problem

Specs driving real database changes through the changefeed showed three gaps:

  • every update reconnected, even a rename: the changed attributes always include updated_at, so no update counted as safe
  • an address (or credentials) change to a broker that wasn't reachable yet was never applied: the retry stopped as soon as it saw the old publisher still running
  • a broker at a new address was never sent the current state, as only brand new brokers triggered a resync

Events are also processed concurrently, so two quick edits could finish out of order.

Fix

  • Apply the Broker as it is in the database now, one change per Broker at a time (per-broker lock)
  • Reconnect only when connection settings change (host, port, tls, auth type, username, password, certificate); anything else is applied to the running publisher
  • Retry until a publisher is connected with the current settings, not merely until one exists. The old publisher keeps running until the replacement connects
  • Republish all state whenever the connection is rebuilt
  • mqtt_broker_manager_spec left its manager running, which took over the sessions of later specs (the "stopped and will not reconnect" errors in the suite)

Testing

New spec/publishing/broker_changes_spec.cr: add, password change, rename, unreachable address that comes up later, resync on address change, quick successive edits, delete. Full suite natively: 86 examples, 1 failure (clear_spec, which fails the same way on master when run natively).

🤖 Generated with Claude Code

Apply the Broker as it is in the database, one change per Broker at a time,
so quick edits finish on the last one and a stale event cannot resurrect a
deleted Broker.

Decide whether to reconnect by comparing connection settings rather than
changed attributes, which always included updated_at. Keep retrying until a
publisher is connected with the current settings, and republish all state
whenever the connection is rebuilt.

Stop the manager mqtt_broker_manager_spec started, which took over the
sessions of later specs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the type: bug something isn't working label Oct 27, 2026
@stakach
stakach merged commit 0446172 into master Oct 27, 2026
11 checks passed
@stakach
stakach deleted the fix/broker-changes branch October 27, 2026 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant