Skip to content
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

Automatic Retry Logic During Connection (DBus) #1220

Closed
ztroop opened this issue Feb 14, 2023 · 4 comments · Fixed by #1255
Closed

Automatic Retry Logic During Connection (DBus) #1220

ztroop opened this issue Feb 14, 2023 · 4 comments · Fixed by #1255
Labels
Backend: BlueZ Issues and PRs relating to the BlueZ backend enhancement New feature or request

Comments

@ztroop
Copy link

ztroop commented Feb 14, 2023

  • bleak version: 0.19.5
  • Python version: 3.10
  • Operating System: Ubuntu 22.04
  • BlueZ version (bluetoothctl -v) in case of Linux: 5.64

Description

It might be worthwhile to have a handler in the library that allows retrying. For example, on rare occasion I may get a bleak.exc.BleakDBusError: [org.bluez.Error.Failed] le-connection-abort-by-local exception. Re-connecting will work. This is a DBus specific problem, I understand... However, it would be ideal to have some sort of retry connection logic baked in. Thoughts on this?

@dlech dlech added the enhancement New feature or request label Feb 14, 2023
@dlech
Copy link
Collaborator

dlech commented Feb 14, 2023

I think this is a good idea. There have been quite a few reports lately of getting an Unreachable error on Windows lately. This lead me to #60 which suggests a retry could be helpful on Windows as well. But since these are very backend-specific, we should probably consider them separate issues.

So rather than a general retry mechanism, I think we should handle these specific errors as needed.

@dlech dlech added the Backend: BlueZ Issues and PRs relating to the BlueZ backend label Feb 14, 2023
@ztroop
Copy link
Author

ztroop commented Feb 15, 2023

I'd been keen to help with the effort. I think tracking and handling "automatic retries" separately in each backend is probably a good idea. I would suggest that this ticket is specific to the bluezdbus.

@ztroop ztroop changed the title Automatic Retry Logic During Connection Automatic Retry Logic During Connection (DBus) Feb 15, 2023
@dlech
Copy link
Collaborator

dlech commented Feb 15, 2023

I'd been keen to help with the effort.

Does this mean you will make a pull request?

@ztroop
Copy link
Author

ztroop commented Feb 15, 2023

I'd been keen to help with the effort.

Does this mean you will make a pull request?

Yeah, I'll put something together when I have some time.

dlech added a commit that referenced this issue Mar 17, 2023
Since BlueZ 6.62, BlueZ has a new connection error
"le-connection-abort-by-local" that is seen quite frequently,
particularly when there are many BLE devices in the area.

Reconnecting immediately after receiving this error is generally
successful, so we add an automatic retry in the BleakClient.

This is a bit tricky because the device does actually connect in this
case and we receive D-Bus property changes indicating this, so we have
to be careful about waiting for the disconnect event before trying
again.

Fixes: #1220
dlech added a commit that referenced this issue Mar 17, 2023
Since BlueZ 6.62, BlueZ has a new connection error
"le-connection-abort-by-local" that is seen quite frequently,
particularly when there are many BLE devices in the area.

Reconnecting immediately after receiving this error is generally
successful, so we add an automatic retry in the BleakClient.

This is a bit tricky because the device does actually connect in this
case and we receive D-Bus property changes indicating this, so we have
to be careful about waiting for the disconnect event before trying
again.

Fixes: #1220
dlech added a commit that referenced this issue Mar 17, 2023
Since BlueZ 6.62, BlueZ has a new connection error
"le-connection-abort-by-local" that is seen quite frequently,
particularly when there are many BLE devices in the area.

Reconnecting immediately after receiving this error is generally
successful, so we add an automatic retry in the BleakClient.

This is a bit tricky because the device does actually connect in this
case and we receive D-Bus property changes indicating this, so we have
to be careful about waiting for the disconnect event before trying
again.

Fixes: #1220
@dlech dlech mentioned this issue Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend: BlueZ Issues and PRs relating to the BlueZ backend enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants