fix: await MQTT unsubscribe tokens during shutdown - #673
Conversation
xe-nvdk
left a comment
There was a problem hiding this comment.
Thanks for the fix, this closes the gap #303 describes and the shape is right: the token wait is bounded, the first failure is preserved while the remaining topics still get their unsubscribe attempt, and the disconnect still always runs. I checked the mock against paho's Token interface (all four methods covered) and ran go test ./internal/mqtt on the branch, which passes.
Two asks before merging:
| s.logger.Info().Msg("Disconnected from MQTT broker") | ||
| s.updateStatus(StatusStopped, "") | ||
|
|
||
| return unsubscribeErr |
There was a problem hiding this comment.
Returning an error here changes behavior at two call sites in manager.go. StopSubscription and PauseSubscription return early when Stop() errors, which skips m.repo.UpdateStatus. At that point the subscriber is already deleted from m.subscribers and the client has disconnected, so the subscription is genuinely stopped while the persisted status keeps saying running, and retrying the stop returns ErrSubscriptionNotRunning, so the status stays wrong until the next start. (ListAutoStart selects on auto_start only, so nothing gets resurrected on restart; this is an API status consistency issue, not a data one.)
An unsubscribe timeout is most likely exactly when the broker is unreachable, so this path will happen in practice. Suggest having those two manager paths persist the status update even when Stop() reports an unsubscribe error, then return the error afterwards.
|
Thank you for catching the manager follow-through. I pushed a1ca9d3
after updating from main.
StopSubscription and PauseSubscription now attempt the persisted
status update even when unsubscribe fails, then return the shutdown
and/or persistence error. I added regression cases for stop and pause
under both broker-error and timeout conditions, checking persisted
status, disconnection, and subscriber removal. The release note is
included under Bug fixes in RELEASE_NOTES_2026.09.2.md, following the
current contribution guide.
Validation: go test ./internal/mqtt; go vet ./internal/mqtt; and the
new manager regression with -race all passed locally. Ready for
another review when convenient.
M Ahmed
|
xe-nvdk
left a comment
There was a problem hiding this comment.
Re-reviewed a1ca9d3. Both asks are addressed: StopSubscription and PauseSubscription now persist the status update regardless of the unsubscribe outcome and return the joined error, and the release notes entry is in place with the credit line. Verified locally on the branch: go test ./internal/mqtt passes, and the new manager regression passes under -race for all four stop/pause x broker-error/timeout cases. Thanks for the thorough test coverage.
Summary
Verification
gofmton changed Go filesgo test ./internal/mqttgit diff --checkCloses #303