Skip to content

Fix shutdown hang when SIGINT arrives during startup#489

Merged
Apollon77 merged 1 commit intomainfrom
fix/shutdown-during-startup
Apr 8, 2026
Merged

Fix shutdown hang when SIGINT arrives during startup#489
Apollon77 merged 1 commit intomainfrom
fix/shutdown-during-startup

Conversation

@Apollon77
Copy link
Copy Markdown
Collaborator

@Apollon77 Apollon77 commented Apr 4, 2026

Summary

  • Fix race condition between start() and stop() when SIGINT/SIGTERM arrives during server initialization
  • stop() now awaits start() completion before tearing down resources, preventing dangling timers/sockets
  • Guard against re-entrant stop() calls from repeated signals
  • Always stop CustomClusterPoller timer in close(), even if the controller hadn't fully started yet

Context

When the Docker container is stopped while the server is still initializing (e.g. during DCL certificate/vendor fetching or BLE setup), stop() runs concurrently with start(). The ControllerCommandHandler.close() returns early because #started is still false, but then start() continues and sets #started = true — leaving the poller timer and controller resources alive. This keeps the Node.js process from exiting, requiring multiple SIGINT/SIGKILL to terminate.

Addresses #454

🤖 Generated with Claude Code

When SIGINT/SIGTERM arrives while the server is still starting up (e.g.
during DCL certificate fetching), stop() and start() race against each
other. start() continues running after stop() completes, leaving timers
and resources alive that keep the process from exiting.

Three changes:
- stop() now awaits start() completion before tearing down resources
- stop() guards against re-entrant calls from repeated SIGINT signals
- CustomClusterPoller.stop() is always called in close(), not guarded
  behind the #started flag that may not be set yet during startup

Addresses #454

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 4, 2026 16:21
Copy link
Copy Markdown
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

Fixes a startup/shutdown race in matter-server so SIGINT/SIGTERM during initialization doesn’t leave timers/resources running and prevent the Node.js process from exiting (notably in Docker).

Changes:

  • Make stop() wait for start() completion (or failure) before tearing down resources, and guard against re-entrant stop calls.
  • Ensure ControllerCommandHandler.close() always stops the CustomClusterPoller, even if the controller never fully started.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/matter-server/src/MatterServer.ts Adds startCompleted + stopping to serialize startup vs shutdown and prevent concurrent teardown/initialization.
packages/ws-controller/src/controller/ControllerCommandHandler.ts Stops CustomClusterPoller unconditionally in close() to avoid leaving its timer running on early shutdown.

@Apollon77 Apollon77 merged commit bff6723 into main Apr 8, 2026
16 checks passed
@Apollon77 Apollon77 deleted the fix/shutdown-during-startup branch April 8, 2026 21:50
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.

2 participants