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

when unsubscribe during long-write, long-write doesn't "finish" and disconnect never "started" #218

Closed
DogsForArms opened this issue Jun 13, 2017 · 5 comments
Assignees
Labels
bug Bug that is caused by the library
Milestone

Comments

@DogsForArms
Copy link

DogsForArms commented Jun 13, 2017

Hello! I have been noticing that if "unsubscribe" is called when a write is ongoing, or a subscribe to change is subscribing, the queued "Disconnect" is not finished. In my case I am noticing it during a long-write. My application is observing a characteristic-change for response, and long-writing. Here is an example of a "unsubscribe" while long-write

D/rxble-writeupdate: 1) observing 297ff612-9a62-4068-9a0c-0a21c4146187
D/RxBle#Radio:   QUEUED RxBleRadioOperationCharacteristicLongWrite(99139398)
D/RxBle#Radio: FINISHED RxBleRadioOperationDescriptorWrite(85537306)
D/RxBle#Radio:  STARTED RxBleRadioOperationCharacteristicLongWrite(99139398)
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/rxble-: - calling unsubscribe here -
D/RxBle#Radio:   QUEUED RxBleRadioOperationDisconnect(77589682)
D/RxBle#Radio:   QUEUED RxBleRadioOperationDescriptorWrite(60563966)
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0
D/RxBle#BluetoothGatt: onCharacteristicWrite characteristic=297ff612-9a62-4068-9a0c-0a21c4146187 status=0

So i start off with "RxBleRadioOperationDescriptorWrite(85537306)" is ongoing, but now it is finished. The long write starts, the disconnect is queued, the long write is disabled but the disconnect never starts. I can see my BLE device says I'm still connected, but subsequent attempts to scan for devices never actually "start". It requires an app reboot then the state is back to normal.

I was seeing the same behaviour when I was waiting for connection.setupNotification(characteristic) or waiting for a normal (small) write, but this is a shorter window and probably harder to hit unsubscribe during.

So as far as steps to reproduce go, I'd say try unsubscribe mid a very "long" write. I do not have an ack strategy (do I need one?). Thanks for your time.

@dariuszseweryn dariuszseweryn self-assigned this Jun 13, 2017
@dariuszseweryn dariuszseweryn added the bug Bug that is caused by the library label Jun 13, 2017
@dariuszseweryn dariuszseweryn added this to the 1.3.1 milestone Jun 13, 2017
@DogsForArms
Copy link
Author

Thanks for the quickness Darius! Let me know if I can provide details or help provide more specific code to reproduce.

@dariuszseweryn
Copy link
Owner

I will create a fix tomorrow and I will ask you to test it. ;)

dariuszseweryn added a commit that referenced this issue Jun 14, 2017
)

#218
#219
This commit fixes a problem: When a long write operation was started there was no way to release the radio when unsubscribe happened. 
Now when unsubscribed the radio is released after a batch of bytes finished writing (no matter if it was a successful or not).
@dariuszseweryn
Copy link
Owner

dariuszseweryn commented Jun 14, 2017

This is now fixed and should be available shortly in 1.3.1-SNAPSHOT. Please try it out and report back if it fixed the behaviour for you or not.

@dariuszseweryn
Copy link
Owner

This is actually a more general problem with unsubscribing from operations while they were running. Should be fixed now but it may use a refactor later on. Please test it and share if it helped.

Best Regards

@DogsForArms
Copy link
Author

Thanks very much! I'll update now and let you know what I see. Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug that is caused by the library
Projects
None yet
Development

No branches or pull requests

2 participants