{"action":"opened","issue":{"url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/483","repository_url":"https://api.github.com/repos/Polidea/RxAndroidBle","labels_url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/483/labels{/name}","comments_url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/483/comments","events_url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/483/events","html_url":"https://github.com/Polidea/RxAndroidBle/issues/483","id":361400329,"node_id":"MDU6SXNzdWUzNjE0MDAzMjk=","number":483,"title":"Rapid connect/disconnect sequence fails to properly disconnect from BLE device","user":{"login":"digitalstreamio","id":19243925,"node_id":"MDQ6VXNlcjE5MjQzOTI1","avatar_url":"https://avatars0.githubusercontent.com/u/19243925?v=4","gravatar_id":"","url":"https://api.github.com/users/digitalstreamio","html_url":"https://github.com/digitalstreamio","followers_url":"https://api.github.com/users/digitalstreamio/followers","following_url":"https://api.github.com/users/digitalstreamio/following{/other_user}","gists_url":"https://api.github.com/users/digitalstreamio/gists{/gist_id}","starred_url":"https://api.github.com/users/digitalstreamio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/digitalstreamio/subscriptions","organizations_url":"https://api.github.com/users/digitalstreamio/orgs","repos_url":"https://api.github.com/users/digitalstreamio/repos","events_url":"https://api.github.com/users/digitalstreamio/events{/privacy}","received_events_url":"https://api.github.com/users/digitalstreamio/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-18T17:09:41Z","updated_at":"2018-09-18T17:09:41Z","closed_at":null,"author_association":"NONE","body":"### Summary\r\nRapid connect/disconnect sequence fails to properly disconnect from BLE device.\r\n\r\nWhen creating subscription to RxBleDevice.establishConnection() and cancelling it prior to connection being established, the physical BLE device remains in connected state (verified through JLink debugger output). This only happens when unsubscribe is called prior to fully establishing connection. If delay is inserted between subscribe/unsubscribe calls, then connect and disconnect sequence works properly.\r\n\r\n### Library version\r\nimplementation \"com.polidea.rxandroidble:rxandroidble:1.6.0\"\r\n\r\n#### Preconditions\r\n - Unsubscribe has to be called prior to connection being established.\r\n\r\n#### Steps to reproduce actual result\r\n1. Create subscription to rxbledevice.establishConnection()\r\n2. Wait 0.2s\r\n3. Call subscription.unsubscribe()\r\n4. On Android: app log shows connection and disconnect operations completing successfully.\r\n5. On BLE Device: JLink debugger output shows that device is still connected.\r\n\r\n#### Minimum code snippet reproducing the issue\r\n\r\n#### Logs from the application running with setting `RxBleLog.setLogLevel(RxBleLog.VERBOSE)`\r\n```\r\n09-18 12:48:54.670 17038-17173/com.livindi.resident I/RxBle#CancellableSubscription: Scan operation is requested to stop.\r\n09-18 12:48:54.673 17038-17173/com.livindi.resident D/BluetoothAdapter: isLeEnabled(): ON\r\n    \r\n    --------- beginning of system\r\n09-18 12:48:54.702 17038-17096/com.livindi.resident D/RxBle#ClientOperationQueue: QUEUED   ScanOperationApi21(185464561)\r\n09-18 12:48:54.703 17038-17092/com.livindi.resident D/RxBle#ClientOperationQueue: STARTED  ScanOperationApi21(185464561)\r\n09-18 12:48:54.704 17038-17173/com.livindi.resident I/RxBle#QueueOperation: Scan operation is requested to start.\r\n09-18 12:48:54.706 17038-17173/com.livindi.resident D/BluetoothAdapter: isLeEnabled(): ON\r\n09-18 12:48:54.709 17038-17051/com.livindi.resident D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=7 mScannerId=0\r\n09-18 12:48:54.715 17038-17092/com.livindi.resident D/RxBle#ClientOperationQueue: FINISHED ScanOperationApi21(185464561) in 12 ms\r\n09-18 12:48:54.733 17038-17173/com.livindi.resident I/RxBle#CancellableSubscription: Scan operation is requested to stop.\r\n09-18 12:48:54.734 17038-17173/com.livindi.resident D/BluetoothAdapter: isLeEnabled(): ON\r\n09-18 12:48:54.885 17038-17197/com.livindi.resident D/RxBle#ClientOperationQueue: QUEUED   ConnectOperation(237633332)\r\n09-18 12:48:54.885 17038-17092/com.livindi.resident D/RxBle#ClientOperationQueue: STARTED  ConnectOperation(237633332)\r\n09-18 12:48:54.888 17038-17173/com.livindi.resident V/RxBle#BleConnectionCompat: Connecting without reflection\r\n09-18 12:48:54.889 17038-17173/com.livindi.resident D/BluetoothGatt: connect() - device: DC:C5:05:C6:9E:0E, auto: false\r\n    registerApp()\r\n    registerApp() - UUID=bf9c3cc7-0ee0-4e7d-8221-6ec65bab636e\r\n09-18 12:48:54.891 17038-17051/com.livindi.resident D/BluetoothGatt: onClientRegistered() - status=0 clientIf=7\r\n09-18 12:48:55.555 17038-17095/com.livindi.resident D/RxBle#ClientOperationQueue: QUEUED   ScanOperationApi21(167195673)\r\n09-18 12:48:55.911 17038-17197/com.livindi.resident D/RxBle#ClientOperationQueue: QUEUED   DisconnectOperation(217206097)\r\n09-18 12:48:55.912 17038-17197/com.livindi.resident I/RxBle#ConnectionOperationQueue: Connection operations queue to be terminated (DC:C5:05:C6:9E:0E)\r\n09-18 12:48:55.913 17038-17196/com.livindi.resident D/RxBle#Executors$RunnableAdapter: Terminated.\r\n09-18 12:48:55.915 17038-17092/com.livindi.resident D/RxBle#ClientOperationQueue: FINISHED ConnectOperation(237633332) in 1029 ms\r\n09-18 12:48:55.916 17038-17092/com.livindi.resident D/RxBle#ClientOperationQueue: STARTED  ScanOperationApi21(167195673)\r\n09-18 12:48:55.918 17038-17173/com.livindi.resident I/RxBle#QueueOperation: Scan operation is requested to start.\r\n09-18 12:48:55.920 17038-17173/com.livindi.resident D/BluetoothAdapter: isLeEnabled(): ON\r\n09-18 12:48:55.925 17038-17051/com.livindi.resident D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=8 mScannerId=0\r\n09-18 12:48:55.930 17038-17092/com.livindi.resident D/RxBle#ClientOperationQueue: FINISHED ScanOperationApi21(167195673) in 14 ms\r\n09-18 12:48:55.932 17038-17092/com.livindi.resident D/RxBle#ClientOperationQueue: STARTED  DisconnectOperation(217206097)\r\n09-18 12:48:55.933 17038-17173/com.livindi.resident D/BluetoothManager: getConnectionState()\r\n    getConnectedDevices\r\n09-18 12:48:55.939 17038-17173/com.livindi.resident D/BluetoothGatt: close()\r\n    unregisterApp() - mClientIf=7\r\n09-18 12:48:55.941 17038-17092/com.livindi.resident D/RxBle#ClientOperationQueue: FINISHED DisconnectOperation(217206097) in 10 ms\r\n```\r\n#### Actual result\r\nBLE Device indicates it is still in connected state and never receives DISCONNECTED event.\r\nINFO [main] on_ble_evt: CONNECTED \r\n\r\n#### Expected result\r\nBLE Device receives DISCONNECTED event\r\nINFO [ble] on_ble_evt: DISCONNECTED. Reason: 0x13 \r\n"}}
{"actor":{"display_login":"digitalstreamio"}}