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

ClientBleGatt.connect Intermittently Hangs #129

Open
WkGl001 opened this issue Mar 14, 2024 · 2 comments
Open

ClientBleGatt.connect Intermittently Hangs #129

WkGl001 opened this issue Mar 14, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@WkGl001
Copy link

WkGl001 commented Mar 14, 2024

Hello,

I've been using ClientBleGatt.connect(...) to connect to a ServerDevice retrieved from scanning. Once in a while, the connect function will hang. I first ran into this while still using version 1.0.7 of this library. I am currently updating to use the latest version, 1.0.15, but I have seen it happen in this latest version as well. The major difference with this newest version is that the connect call can now be cancelled so it is at least recoverable.

This issue has been difficult to reproduce in a normal environment. I've only been able to reproduce this semi-reliably by either:

  1. Having the nRF Connect app connect to the bluetooth device that I'm using first and then connecting to it through my own application.
  2. Using breakpoints in a debugger when connecting with my own application.

From what I've seen poking around in the library so far, it looks like there may be a race condition after connectGatt is called on the BluetoothDevice object with the gattCallback (ClientBleGattFactory.kt line 167) between when that gattCallback gets a connection state change to propagate into the ClientBleGatt object and when the ClientBleGatt::waitForConnection function sets the onConnectionStateChangedCallback (ClientBleGatt.kt line 183) so that it can be resumed.
The callback passed into Android can be called asynchronously. I have seen the connection state change event get triggered and propagated on one thread before the ClientBleGatt's waitForConnection could set its own onConnectionStateChangedCallback on another thread.

Thank you.

@philips77 philips77 added the bug Something isn't working label Mar 18, 2024
@philips77
Copy link
Member

Hi, I'm working on rewriting the library. New version won't be backwards compatible, as there's too many changes.

@waqasakrambueid
Copy link

I am also having this same issue when Connect hangs and never releases. I spent almost a week investigating this and found that someone is a race condition and it is somehow bug internally in the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants