Skip to content

Commit

Permalink
fix: ensure we back off for longer when out of slots (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 24, 2022
1 parent a5e08c6 commit efeced3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/bleak_retry_connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,14 @@ def address_to_bluez_path(address: str, adapter: str | None = None) -> str:

def calculate_backoff_time(exc: Exception) -> float:
"""Calculate the backoff time based on the exception."""
if isinstance(exc, BleakOutOfConnectionSlotsError):
return BLEAK_OUT_OF_SLOTS_BACKOFF_TIME
if isinstance(
exc, (BleakDBusError, EOFError, asyncio.TimeoutError, BrokenPipeError)
):
return BLEAK_DBUS_BACKOFF_TIME
if isinstance(exc, BleakError) and any(
error in str(exc) for error in OUT_OF_SLOTS_ERRORS
):
return BLEAK_OUT_OF_SLOTS_BACKOFF_TIME
return BLEAK_BACKOFF_TIME


Expand Down
6 changes: 5 additions & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,11 @@ def test_calculate_backoff_time():
== BLEAK_DBUS_BACKOFF_TIME
)
assert (
calculate_backoff_time(BleakOutOfConnectionSlotsError())
calculate_backoff_time(
BleakError(
"No backend with an available connection slot that can reach address EB:4A:D4:93:68:EF was found"
)
)
== BLEAK_OUT_OF_SLOTS_BACKOFF_TIME
)

Expand Down

0 comments on commit efeced3

Please sign in to comment.