muka / go-bluetooth

Golang bluetooth client based on bluez DBus interfaces

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question about Discovering IBeacon

opened this issue · comments

I have being using the example in https://github.com/muka/go-bluetooth/blob/master/examples/discovery/discovery.go to write some code that will discover an IBeacon. However I when using the channel returned from beacon.WatchDeviceChanges(ctx) I am running to a go routine leak. According to the sample you wait until a true value is sent on the channel to determine if the device is an iBeacon or not. In my code if it receive false or never receive anything on the channel after a period of time (1 min), I quit listening and close the context. However this leads to the creation of go routines in dbus.inWorker that never get closed. My question is what is the best way to stop listening to channel returned from WatchDeviceChanges without causing runaway routines in the dbus package? I would assume canceling the context used when calling WatchDeviceChanges would clean everything up, but that does not seam to be the case.

The run away go routines are actually created in the deliver func on the defaultHandler of the DBUS package. If the signal channel is closed without first calling RemoveSignal then a go routine will start and endlessly wait here. Calling UnwatchProperties on Device1, will unregister for receiving PropertyChanged updates which eventually call RemoveSignal. This prevents the deferredDeliver go routine for being created.