BLE CORDIO: Recovering when errors occur during GATT Client launchServiceDiscovery process

The application is a GATT client, built on mbed-os-5.12.2

We have been seeing the following issues when launching the discovery process , we are looking for a specific service and characteristic with a specific UUID, once we have successfully connected to a peripheral.

ex:

//launching the discovery service.
ble_error_t error = m_ble.gattClient().launchServiceDiscovery(event.getConnectionHandle(),
asFunctionWithContext(&TestBleClass::OnServiceDiscovery),
asFunctionWithContext(&TestBleClass:OnCharacteristicDiscovery),
TESTSENSOR_SERVICE_UUID,
TESTSENSOR_CHARACTERISTIC_UUID);

  1. The LaunchServiceDiscovery process terminates, prematurely even before the service discovery callback or the characteristic discovery call back is invoked or even called for that matter, as a result we can’t seem to launch the characteristic descriptors discovery to subscribe to notification. Shouldn’t the OnDiscoveryTermination method be called after the service discovery and characteristic discovery call backs have been invoked?

  2. If we keep attempting to launchServiceDiscovery process we get the ble error BLE_ERROR_INVALID_STATE.

  3. Sometime during the launch Discovery process, the connection may get terminated, we get the disconnect termination reason with a reason code of 8 or 22 or 62. Where are the definitions for these disconnection reasons defined?

So my question is how do we gracefully recover from the launch Discovery errors , so that we can resume reading/writing from /to a characteristic or subscribing for notifications.

Also the GATT Client reset method, would it help in these scenarios?

Thanks,
Ajay

Any thoughts, @sayhuthut, @vcoubard.

Also is there a way to invoke the Service Discovery class, reset method?

Thanks,
Ajay