Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
Component used: androidx.bluetooth Version used: 1.0.0-alpha02 Devices/Android versions reproduced on: Pixel 8 Pro
Within the GattClient, the
fwkBluetoothGatt?.close()
andfwkBluetoothGatt?.disconnect
are called within the closeGatt of your FrameworkAdapterBase.The fwkAdapter.closeGatt is called in an invokeOnCompletion callback that is registered only after a connection is established. However, this is an issue, because connections that are never established and hit the 30seconds timeout, do not cleanup the bluetoothGatt resources and after a certain period of time, connections are not allowed anymore.
Example logs, observe clientIf
The issue stems from the fact that withTimeout(CONNECT_TIMEOUT_MS) within the GattClient.connect(..) suspends and then throws a TimeoutCancellationException, which cancels the whole coroutineScope of the connect method, before the invokeOnCompletion handler is setup and thus the bluetooth gatt is never closed.
Once we cycle through 32 GATT_MAX_APPS connections, we can never reconnect anymore, until the app is restarted or bluetooth is turned off and on. No matter if the peripheral is nearby or not.
Ideally the invokeOnCompletion handler should be set immediately after the gatt is created and before the withTimeout.
Current implementation:
Proposed patch
Thanks.