kable icon indicating copy to clipboard operation
kable copied to clipboard

Cancelling scope of observation prevents restarting observation after creating new scope

Open twyatt opened this issue 2 years ago • 6 comments

As reported on Slack, observation isn't starting after a previous observation is cancelled (and remote peripheral is powered off and back on). Upon reconnecting, setCharacteristicNotification is not called to enable the observation.

Reproduction steps were said to be:

  1. Observe a characteristic.
  2. Cancel the scope of observation.
  3. Turn off the peripheral (hardware) and turn on it.
  4. Reconnect with the peripheral.
  5. Observe the characteristic again.

twyatt avatar Jul 17 '22 07:07 twyatt

Travis, I see that didStartNotification = false is not called in stopObservation

Seems that handler.stopObservation(characteristic) hangs forever. But I didn't understand the reason. I changed the order of the call and solving this issue, but I can't tell you if is the expected behaviour because handler.stopObservation(characteristic) is not completed.

private suspend fun stopObservation() {
    didStartObservation = false
    suppressConnectionExceptions {
        handler.stopObservation(characteristic)
    }
}

francismariano avatar Jul 18 '22 20:07 francismariano

@twyatt the handler.stopObservation(characteristic) described above calls setConfigDescriptor(platformCharacteristic, enable = false) but setConfigDescriptor never is completed.

setConfigDescriptor calls write(configDescriptor, DISABLE_NOTIFICATION_VALUE) but never is completed.

the write function calls connection.execute I unable to debug but it never is completed.

francismariano avatar Jul 19 '22 15:07 francismariano

the write function calls connection.execute I unable to debug but it never is completed.

Thanks for investigating this! This will be super helpful when I find some time to dig into this.

twyatt avatar Jul 19 '22 17:07 twyatt

Unfortunately I don't have time to reproduce the issue, so I'm shooting blind with this fix. If someone is able to test and validate if it actually fixes the issue, it would be much appreciated:

repositories {
    maven("https://oss.sonatype.org/content/repositories/snapshots")
}

dependencies {
    implementation("com.juul.kable:core:0.18.0-issue-358-1-SNAPSHOT")
}

twyatt avatar Aug 03 '22 01:08 twyatt

I've been running with and without this snapshot for the last 8 days and it definitely seems to fix both the issues described above. Thanks @twyatt for fixing and @francismariano for defining the issue! 🎉

ebabel avatar Aug 10 '22 20:08 ebabel

Thanks for testing/validating the snapshot @ebabel! I've taken the PR out of draft.

twyatt avatar Aug 10 '22 20:08 twyatt