Establish connection does not close operation on the specified timeout
See original GitHub issueSummary
When I add a timeout to establishConnection
the operation is not timed out within the specified time but will throw a BleDisconnectedException with error code 133 instead.
Library version
1.9.0
Preconditions
Have an existing bonding with a device and make sure you turn the bledevice off so it will not respond to the call.
Reproduced the issue on a Google Pixel (Android P) .
Steps to reproduce actual result
1. Make sure the device is switched off
2. Start the app and wait around 6 seconds to establish connection
Minimum code snippet reproducing the issue
fun connectToDevice(deviceId: String): Observable<RxBleConnection> {
Timber.d("RXBLE connecting with device $deviceId")
return rxBleClient.getBleDevice(deviceId)
.establishConnection(false, Timeout(6000, TimeUnit.MILLISECONDS))
.doOnError {
Timber.d("RXBLE WHOOPS error connecting device: $deviceId error:( $it) ")
}
.doOnTerminate{
Timber.d("RXBLE terminator establish conn to device: $deviceId terminated ")
}
}
Logs from the application running with setting
2019-03-25 18:53:15.830 24619-24619/com.remonh87 D/MyBleClient: RXBLE connecting with device 12:34:55:66:77:88
2019-03-25 18:53:15.899 24619-24680/com.remonh87 D/RxBle#ClientOperationQueue: QUEUED ConnectOperation(137016935)
2019-03-25 18:53:15.901 24619-24667/com.remonh87 D/RxBle#ClientOperationQueue: STARTED ConnectOperation(137016935)
2019-03-25 18:53:15.902 24619-24667/com.remonh87 I/RxBle#ClientOperationQueue: RUNNING ConnectOperation{MAC='12:34:55:66:77:88', autoConnect=false}
2019-03-25 18:53:15.918 24619-24682/com.remonh87 V/RxBle#BleConnectionCompat: Connecting without reflection
2019-03-25 18:53:37.154 24619-24637/com.remonh87 I/RxBle#GattCallback: MAC='12:34:55:66:77:88' onConnectionStateChange(), status=133, value=0
2019-03-25 18:53:37.174 24619-24637/com.remonh87 D/RxBle#ConnectionOperationQueue: Connection operations queue to be terminated (MAC='12:34:55:66:77:88')
com.polidea.rxandroidble2.exceptions.BleDisconnectedException: Disconnected from MAC='12:34:55:66:77:88' with status 133 (GATT_ERROR)
at com.polidea.rxandroidble2.internal.connection.RxBleGattCallback$2.onConnectionStateChange(RxBleGattCallback.java:77)
at android.bluetooth.BluetoothGatt$1$4.run(BluetoothGatt.java:262)
at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:770)
at android.bluetooth.BluetoothGatt.access$200(BluetoothGatt.java:39)
at android.bluetooth.BluetoothGatt$1.onClientConnectionState(BluetoothGatt.java:257)
at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:71)
at android.os.Binder.execTransact(Binder.java:731)
2019-03-25 18:53:37.180 24619-24679/com.remonh87 V/RxBle#Executors: Terminated (MAC='12:34:55:66:77:88')
2019-03-25 18:53:37.181 24619-24637/com.remonh87 D/MyBleClient$connectToDevice: RXBLE WHOOPS error connecting device: 12:34:55:66:77:88 error:( com.polidea.rxandroidble2.exceptions.BleDisconnectedException: Disconnected from MAC='12:34:55:66:77:88' with status 133 (GATT_ERROR))
2019-03-25 18:53:37.184 24619-24637/com.remonh87 D/MyBleClient$connectToDevice: RXBLE terminator establish conn to device: 12:34:55:66:77:88 terminated
Actual result
Operation will be terminated after approx 22 seconds
Expected result
Establishconnection should fail on the desired timeout of 6 seconds
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Establish connection does not close operation on the ... - GitHub
When I add a timeout to establishConnection the operation is not timed out within the specified time but will throw a BleDisconnectedException ...
Read more >How to established a connection and not closing it after ...
1 Answer 1 ... Try using socket.settimeout(time). Alternatively, get the system time when the socket was opened, and the current system time, and ......
Read more >Timeout expired messages when connecting to SQL Server
A timeout error means that a certain operation takes longer than needed. ... If connections aren't closed correctly, errors may occur.
Read more >Connection Timeout vs. Read Timeout for Java Sockets
From the client side, the “read timed out” error happens if the server is taking longer to respond and send information. This could...
Read more >Common Reasons Why Connections Stay Open for a Long ...
If the value is 0, then close has been called by the application. If the value is 1 or higher, the application has...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I will keep this opened until the Javadoc fix will be in the
master
branch.As for your issue — connecting may be cancelled by the user externally (e.g. by using
.timeout()
operator) and the next connect may then proceed. Just keep in mind that there is an Android OS bug that may show itself thenThank you for pointing this out.
Yup. It seems that the documentation is indeed misleading:
It should be something like the below to match the current behaviour:
To have
Establishconnection should fail on the desired timeout of 6 seconds
one may simply usedevice.establishConnection(autoConnect).timeout(6, TimeUnit.SECONDS)
— there is no need to bake it into the library APIWhat do you think?