Fix shutdown hang when SIGINT arrives during startup#489
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
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 forstart()completion (or failure) before tearing down resources, and guard against re-entrant stop calls. - Ensure
ControllerCommandHandler.close()always stops theCustomClusterPoller, 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. |
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
start()andstop()when SIGINT/SIGTERM arrives during server initializationstop()now awaitsstart()completion before tearing down resources, preventing dangling timers/socketsstop()calls from repeated signalsCustomClusterPollertimer inclose(), even if the controller hadn't fully started yetContext
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 withstart(). TheControllerCommandHandler.close()returns early because#startedis stillfalse, but thenstart()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