Fix gateway/group startup and teardown race conditions#690
Open
Fix gateway/group startup and teardown race conditions#690
Conversation
6e8fb32 to
24d076d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #690 +/- ##
==========================================
+ Coverage 97.51% 97.60% +0.08%
==========================================
Files 62 62
Lines 10949 10971 +22
==========================================
+ Hits 10677 10708 +31
+ Misses 272 263 -9 ☔ 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.
This pull request introduces several improvements to error handling, task management, and group operations in the Zigbee gateway and group management modules. The changes help prevent potential issues like race conditions, redundant task creation, and errors from missing entities or groups. The most important changes are grouped below by theme.
Task Management & Error Handling
device_initializedto ensure tasks are only removed if they match the expected task, preventing race conditions.device_removed, ensuring cleanup of background tasks.async_initialize_devices_and_entitieswith atry/finallyto always allow polling after attempting device polling, improving robustness.shutdownwithtry/finallyto guarantee that the shutdown state is reset even if errors occur. [1] [2]helpers.pyby checking if tasks are already running before starting new ones. [1] [2]Group Operations
group_removedto avoid errors when removing groups that don't exist, with debug logging for visibility.unregister_group_entityto refresh entity subscriptions after removing a group entity, ensuring correct subscription state.async_add_membersandasync_remove_membersif the member list is empty, preventing unnecessary processing. [1] [2]Configuration Handling
get_application_controller_datato avoid unintended mutation of config objects.## SummaryFixes gateway/group lifecycle race conditions around startup polling, shutdown behavior, init task races, and group/member lifecycle bookkeeping.
Failing tests addressed
tests/test_gateway.py::test_group_removed_unknown_group_is_nooptests/test_gateway.py::test_country_code_passthrough_updates_when_changedtests/test_gateway.py::test_group_async_add_members_empty_list_nooptests/test_gateway.py::test_group_async_remove_members_empty_list_nooptests/test_gateway.py::test_group_unregister_entity_clears_member_subscriptionstests/test_gateway.py::test_shutdown_controller_exception_resets_shutting_down_flagtests/test_gateway.py::test_startup_polling_failure_still_enables_allow_pollingtests/test_gateway.py::test_device_removed_cancels_pending_device_init_tasktests/test_gateway.py::test_global_updater_second_start_stop_cancels_first_tasktests/test_gateway.py::test_gateway_device_initialized_done_callback_race_keeps_newer_tasktests/test_gateway.py::test_device_availability_checker_start_twice_stop_once_cancels_all_tasksVerification
pytest(branch-local targeted run): all listed tests pass.