Fix race condition: await remove_all_listeners() in on_shutdown#311
Merged
NodeJSmith merged 3 commits intomainfrom Feb 24, 2026
Merged
Fix race condition: await remove_all_listeners() in on_shutdown#311NodeJSmith merged 3 commits intomainfrom
NodeJSmith merged 3 commits intomainfrom
Conversation
ServiceWatcher, StateProxy, and AppHandler called Bus.remove_all_listeners() without awaiting the returned Task, creating a race condition where listeners could survive shutdown if the task bucket was cancelled first.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a race condition in shutdown handlers where Bus.remove_all_listeners() was called without await, potentially allowing listeners to survive shutdown if the task bucket was cancelled before cleanup completed.
Changes:
- Added
awaitto threeremove_all_listeners()calls inon_shutdown()methods - Fixed test fixture to return an awaitable Task instead of a plain Mock
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/hassette/core/state_proxy.py | Added await to remove_all_listeners() call in on_shutdown() |
| src/hassette/core/service_watcher.py | Added await to remove_all_listeners() call in on_shutdown() |
| src/hassette/core/app_handler.py | Added await to remove_all_listeners() call in on_shutdown() |
| tests/integration/test_state_proxy.py | Updated mock to return awaitable Task via asyncio.ensure_future() |
| CHANGELOG.md | Added entry documenting the fix |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #311 +/- ##
=======================================
Coverage 79.99% 79.99%
=======================================
Files 134 134
Lines 9531 9531
Branches 943 943
=======================================
Hits 7624 7624
- Misses 1538 1539 +1
+ Partials 369 368 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
Bus.remove_all_listeners()returns anasyncio.Taskbut threeon_shutdownmethods (ServiceWatcher,StateProxy,AppHandler) called it withoutawait, creating a race condition where listeners could survive shutdown if the task bucket was cancelled firstawaitto all three call sites and fixed the test fixture mock to return an awaitable taskCloses #309