Skip to content

mqtt-hivemq: restore client subscriptions when a handler registers again - #277

Closed
tipatterson-dev wants to merge 3 commits into
masterfrom
bugfix/mqtt-hivemq/269-restore-handler-subscriptions
Closed

tipatterson-dev wants to merge 3 commits into
masterfrom
bugfix/mqtt-hivemq/269-restore-handler-subscriptions

Conversation

@tipatterson-dev

@tipatterson-dev tipatterson-dev commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Fixes lost subscriptions in the HiveMQ extension: after a handler module restarted, clients that were already subscribed got no more messages.

Closes #269. Part of #249. Needs #262, which is merged: this branch starts from it. The PR targets master.

Problem

When a module that registers an MQTT handler restarts while the MQTT Server runs, HiveMQ and OshExtension keep the client subscriptions. The new handler never got onSubscribe for them, so it published nothing to those clients. A new SUBSCRIBE to the same topic was accepted but did not help, because the topic was already recorded. The client had to unsubscribe and subscribe again, or reconnect. This affects every module that registers a handler.

Fix

  • OshExtension keeps the user of each client subscription.
  • registerHandler calls onSubscribe for the existing subscriptions under the prefix of the new handler.
  • If onSubscribe fails (for example, the resource is gone or the user lost the permission), the subscription is removed from the client in HiveMQ.
  • Module version 0.1.1 to 0.1.2.

Testing

  • New tests in TestOshExtension:
    • a restarted handler gets the existing subscriptions with the correct users, and a new SUBSCRIBE to the same topic does not count the client twice
    • a subscription that the handler refuses is removed from the client
    • only the topics of the new handler are restored

Merge order

  1. mqtt-hivemq: re-check permissions when a rejected subscribe is retried #262 re-check permissions on a retried subscribe (merged)
  2. This PR

@tipatterson-dev tipatterson-dev added the bug Something isn't working label Nov 12, 2026
@tipatterson-dev tipatterson-dev self-assigned this Nov 12, 2026
@tipatterson-dev
tipatterson-dev changed the base branch from bugfix/mqtt-hivemq/257-subscribe-recheck to master November 12, 2026 16:27
@tipatterson-dev

Copy link
Copy Markdown
Member Author

Closed in favor of #267. That PR contains the same fix for #269 (the same changes to OshExtension and TestOshExtension), and its wildcard check for restored subscriptions needs it. #267 now closes #269. The module version there is 0.2.0, so the 0.1.2 of this PR is not used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mqtt-hivemq: subscriptions stop getting messages after a handler module restarts

1 participant