-
Notifications
You must be signed in to change notification settings - Fork 54
Fix race condition when decrypting notifications during lock disconnection #368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
🚀 New features to boost your workflow:
|
You should have access to push to this PR. Feel free to adjust. I won't have time to look soon given it's a holiday in the US |
SwitchbotModel.LOCK_ULTRA, | ||
], | ||
) | ||
def test_notification_handler_during_disconnect( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could really use a good end to end test framework, but since we don't have one, this will have to do
I'll do a release |
ok, Thanks @bdraco ! |
Fix race condition when decrypting notifications during lock disconnection
Fixes #353
Problem
A race condition occurs when encrypted notifications arrive during device disconnection:
_decrypt
fails withRuntimeError: Cannot decrypt: IV is None
This timing-dependent issue is hard to reproduce and may vary across Bluetooth stacks.
Solution
Modified
_notification_handler
inswitchbot/devices/lock.py
to check the_expected_disconnect
flag and skip processing lock notifications during expected disconnection. This prevents the race condition where notifications with encrypted data arrive after the IV has been cleared.Changes
_notification_handler
to return early if_expected_disconnect
is True_decrypt
from being called with None IV during disconnectionTesting