mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-27 16:48:58 +00:00
a84d7ca0b3
The MQTT target spawned its rumqttc event loop exactly once through a `OnceCell`. When the loop exited on a fatal protocol error, the finished `JoinHandle` stayed in the cell, so `init()` never respawned it. The target then went permanently silent: `publish` calls kept enqueuing but nothing was ever delivered, while the target still looked healthy. Replace the one-shot spawn with a supervisor task. The `OnceCell` now guards a single supervisor that runs one event-loop session at a time and, when a session exits, rebuilds the client and event loop from the latest `MqttOptions` after an exponential backoff (1s..30s). A session that connected resets the backoff so a transient drop reconnects promptly; repeated immediate failures back off to avoid a reconnect storm. Cancellation from `close()` is handled by the supervisor dropping the in-flight session future, so no per-session cancel channel is needed. Rebuilding options per session also keeps TLS hot-reload working across reconnects. The backoff policy is a pure function and the supervisor loop is generic over the session runner, so both are unit tested without a broker: one test asserts the session restarts repeatedly until cancelled, another that a live session stops promptly on cancel. Refs: https://github.com/rustfs/backlog/issues/972