Skip to content

EnableNotifications doesn't properly close underlying goroutines/channels #168

@sbinet

Description

@sbinet

on Linux, DeviceCharacteristic.EnableNotifications calls WatchProperties and StartNotify on gatt.GattCharacteristic1.

but (as #106 noted) it doesn't call StopNotify nor UnwatchProperties.
this means the goroutine spawned by WatchProperties isn't properly closed nor collected.

(and it seems to me, client code can't call EnableNotifications again, once the first set of notifications has been collected.
another Device has to be created and connected anew)

the current API doesn't seem to easily allow for early cancellation of notifications either.

bluez seems to inject a poison pill (a nil value) into the channel and close it when UnwatchProperties is called.
so we'd need to drain that channel inside EnableNotifications.

to achieve proper goroutine collection and support early cancellation, we could either:

  • modify the signature of the callback function to return an error and specify a special value for early cancellation, or
  • modify the signature of EnableNotifications to take an additional parameter (either a context.Context or chan struct{}) so user could notify us when to call StopNotify+UnwatchProperties

WDYT ?

(I don't know how to handle this for other platforms/OSes)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions