-
Notifications
You must be signed in to change notification settings - Fork 306
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
Code hangs when BLE client disconnects first #219
Comments
I'm digging in on this one. |
Hi @Ladvien Thanks for your suggestion - I agree that there must be a better way to fix this than what I did... I tried using the ConnectionDone exception, as well as a number of others, but the code still hangs, and no exception is raised. I will keep trying to see if I can find a better solution or at least get a better handle on what's going on. |
Hello @BillMicro, Well, I've dug pretty deep. I'm not sure, but it seems like something is happening in the |
Hi @Ladvien I'll take a look at that, as well as trying to understand the basics of how |
When server (BLE device) disconnects before bleak does, the code hangs when BleakClientBlueZDBus.__aexit__() calls BleakClientBlueZDBus.disconnect(). This is temporarily fixed here with a disconnection state variable.
Oh nice! Thank you for sharing. It looks like the Proglove folk are using bleak in testing or production. That's great. It's a huge project and would feel bad if Henrik had to maintain it on his own. I took a look at their additions, they mention a "leaky event loop" on POSIX systems. I'm guessing that's what we were seeing. Glad there are smarter, more experienced people out there than me. :) |
This is troublesome indeed. An exception is desired, not a complete hanging... This will be looked at in a later release though. Other issues have precendence right now. |
bluetoothctl -v
) in case of Linux: 5.50Description
When connecting to a BLE device, if the client disconnects first, bleak seems to hang. This issue was fixed by modifying bluezdbus\client.py.
What I Did
I ran the notifications example "enable_notifications.py", connecting to a custom-built BLE device. This device was guaranteed to disconnect from the client before the 5 second asyncio.sleep had completed. I only modified it by commenting out the stop_notify line (no longer needed) and by adding a logging line after the BleakClient section, which never ran.
In order to debug this problem, logger statements were added to bluezdbus\client.py, which made it clear that the code was hanging on BleakClient.disconnect when called by BleakClient.aexit, during the following section:
This was fixed by making the following changes to bluezdbus\client.py:
However, this is a non-satisfactory solution. It can be be found here: 8794eac
The text was updated successfully, but these errors were encountered: