-
Notifications
You must be signed in to change notification settings - Fork 302
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
Fix handling of a device being removed from the bus while we are waiting for a change #1329
Conversation
new behavior after change
|
I haven't had a chance to come back to this as I had to do a trip unexpectedly and won't be back home until the end of the month to get a good test on validating this fix. |
It's actually worse because the callback what waits for the state to change has an untrapped key error so the state never resolved because it tries to access the device that is no longer there |
bleak/backends/bluezdbus/manager.py
Outdated
if device_path not in self._properties: | ||
raise BleakError( | ||
f"Device '{device_path}' disappeared while waiting to discover services" | ||
) |
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.
If we don't check here, we could end up with an unretrieved exception when calling _wait_condition
since it will raise KeyError
bleak/backends/bluezdbus/manager.py
Outdated
raise BleakError( | ||
f"Device '{device_path}' disappeared while waiting to discover services" | ||
) | ||
|
||
services_discovered_wait_task = asyncio.create_task( |
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.
These would wait forever if the device is removed from the bus after we start waiting for the callback which is likely the problem in home-assistant/core#93171
I adjusted the opening text a bit to try to better explain whats going on here |
@dlech Sorry to ask again. Hopefully you can find some time for this one as its blocking some other fixes now. |
I have proposed an alternative to synthesizing the It looks like there are some other changes here to fix linting issues and perhaps some performance improvements as well? Happy to take those as separate commits. |
Looks good sans the exception handling you already commented on
I'll break out the code that reduces the linear searches into a fresh PR after #1399 merges to reduce the chance of conflicts |
This was split out into other pull requests. |
We could wait forever if the device was removed from the bus as the
_wait_condition
callback would never fire because we would can getInterfacesRemoved
beforePropertiesChanged
(which currently results inpass
edKeyError
in thePropertiesChanged
path).This was presented as a long wait when a connection fails if the device is removed from the bus because the connection state change callback will never fire as the device gets removed after the
le-connection-abort-by-local
or the adapter runs out of slots.This fix is blocking another fix: esphome/aioesphomeapi#528 (see Bluetooth-Devices/bleak-retry-connector#101 for more info)
The reason everything didn't stall completely in Home Assistant as we have everything wrapped in
async_timeout
as an additional safety.