Asyncio task hang during connection attempt #1591
Labels
Backend: BlueZ
Issues and PRs relating to the BlueZ backend
more info required
Issues does not have a reproducible test case, has insufficent logs or otherwise needs more feedback
bluetoothctl -v
) in case of Linux: 5.69Description
Every time there is an attempt to connect to a device and during this attempt the device disappears, the task performing the attempt to connect hangs.
We found an uncaught
asyncio.exceptions.CancelledError
on dbus-fast/aio/message_bus.py on the implementation of thecall
method, where it awaits for a reply to the performed d-bus call.We quickly fixed this by catching this exception on dbus-fast.
Even though this exception gets caught and raised, and later caught in bleak
client.py
it still hangs.What I Did
We implemented a program that scans using a characteristic filter, periodically during 5sec.
At the end of each scanning period it sorts and filters a list of devices based on the average RSSI values(and some other calculations) and attempts to connect to some of them.
This connection is done to one device at a time, and of course after disabling the scanner (also passing the
BLEDevice
to theBleakClient
constructor). We did implement a few variations, one of them spawns one task per device, using a lock whenever we are either connecting+subscribing to characteristics, another just attempts to connect inside the same task that scans.Both approaches work quite well, unless one of the target devices disappears during the connection attempt, as described previously.
Logs
We will soon provide a code sample with a similar implementation to what we have and corresponding logs so we can provide a clean output and not expose information that is inherent to our application.
The text was updated successfully, but these errors were encountered: