Skip to content

fix: improve startup signals behavior#31130

Merged
Koenkk merged 5 commits intodevfrom
controller-signals
Feb 24, 2026
Merged

fix: improve startup signals behavior#31130
Koenkk merged 5 commits intodevfrom
controller-signals

Conversation

@Nerivec
Copy link
Collaborator

@Nerivec Nerivec commented Feb 21, 2026

  • optimize imports in index.js
  • add JS typing in index.js
  • pass possible SIG to Controller stop
  • add a few guards to prevent undesired errors in "aborted startup" scenario
  • optimize passlist/blocklist behavior on startup, no unnecessary looping, move some ops outside of loop
  • add "stopping" log in Controller to align behavior (starting, started, stopping, stopped)
    • e.g.: Stopping Zigbee2MQTT (restart=false, code=0, signal=SIGINT)
  • use AbortController in Controller to abort startup sequence if necessary (mainly to prevent start+stop running concurrently on SIG which creates uncontrolled behaviors)
    • pass abort signal to Zigbee start and various nested calls that are possibly "long-running"
    • use return instead of throw to avoid clashing with rest of logic (would have to check error otherwise...)
    • no-op once startup finished

@Koenkk if you see a better way to do this... 😛

CC: @burmistrzak @sjorge @andrei-lazarov if you have some time to review this 😉

TODO:

  • pass abort signal to ZH (need impl. in ZH)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves Zigbee2MQTT startup/shutdown behavior when receiving signals by making startup abortable, hardening stop paths during partially completed startup, and optimizing passlist/blocklist handling.

Changes:

  • Add AbortController-based startup aborting and pass signal context into Controller.stop().
  • Harden shutdown paths to avoid errors when stop occurs mid-startup (Zigbee/MQTT/state/onEvent).
  • Optimize passlist/blocklist processing on Zigbee startup and extend tests for aborted-startup scenarios.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
index.js Refactors startup script imports and adds JSDoc typing; passes signal into controller stop.
lib/controller.ts Introduces abortable startup sequence and logs “Stopping …” with signal/code/restart context.
lib/zigbee.ts Adds abort checks during Zigbee startup and optimizes passlist/blocklist removal behavior.
lib/mqtt.ts Adds guard to avoid publishing offline state when MQTT client isn’t initialized.
lib/state.ts Guards state cleanup logic during stop when Zigbee wasn’t fully started.
lib/extension/onEvent.ts Guards stop-time onEvent calls when Zigbee wasn’t fully started.
test/controller.test.ts Adds coverage for aborts during different startup phases; extends blocklist test.
test/mocks/mqtt.ts Adds missing vi import for mock function usage.

@Nerivec Nerivec marked this pull request as ready for review February 24, 2026 19:08
@Koenkk Koenkk merged commit f8385b8 into dev Feb 24, 2026
14 checks passed
@Koenkk Koenkk deleted the controller-signals branch February 24, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants