Repository navigation
🐛 [TRIGGER] Prevent MQTT trigger from crashing process when broker is disconnected (fixes #1520) - #1528
Merged
Conversation
… disconnected (fixes #1520)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
When a container hosting the MQTT broker is updated (for example, by the
dockercomposetrigger), the broker container stops and is temporarily removed before being recreated. During this window, the Docker watcher detects container lifecycle changes and emitscontainerAdded/containerUpdatedevents.Previously,
Mqtt.tsregistered event listeners callingthis.trigger(container)directly without catching rejected promises. Because the MQTT client is disconnected during broker restart (this.client.connected === false),Mqtt.trigger()threwError('MQTT client is not connected'). In Node.js, an unhandled rejection in anEventEmitterlistener terminates the process, causing WUD to crash and leaving the broker container stopped and removed before the update flow could complete.Fix Details
onContainerAddedandonContainerUpdatedinMqtt.tsintry ... catchblocks that log a warning and debug information without letting unhandled promise rejections escape.Mqtt.deregisterComponent().Hass.tswithtry ... catchblocks to avoid unhandled rejections during broker disconnections.handleContainerReport,handleContainerReports,handleContainerUpdatePre,handleContainerPreload, and listener registrations inTrigger.tsto ensure top-level exception handling.e: anycatch blocks with strict TypeScripte: unknown.app/triggers/providers/mqtt/Mqtt.test.tsverifying thatcontainerAddedandcontainerUpdatedhandle disconnected client scenarios gracefully without throwing unhandled rejections.deregisterComponentproperly unregisters container listeners.website/docs/changelog/next.mdunder Bug Fixes, maintaining strict categorization and alphabetical sorting.Fixes #1520