Fix race while disconnecting after connect timeout (#295)

This commit is contained in:
J. Nick Koston 2022-10-30 17:26:09 -05:00 committed by GitHub
parent 770cd70f73
commit cb6b1595b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -484,10 +484,11 @@ class APIClient:
await event.wait()
except asyncio.TimeoutError as err:
unsub()
# Disconnect before raising the exception to ensure
# the slot is recovered before the timeout is raised
# to avoid race were we run out even though we have a slot.
await self.bluetooth_device_disconnect(address)
raise TimeoutAPIError("Timeout waiting for connect response") from err
finally:
if not event.is_set():
await self.bluetooth_device_disconnect(address)
return unsub