Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Revert back to reflect.Ptr #182

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Revert back to reflect.Ptr #182

wants to merge 5 commits into from

Commits on Mar 18, 2023

  1. Revert back to reflect.Ptr

    This allows the module to be compiled using go 1.14, as specified in the go.mod file.
    amrbekhit committed Mar 18, 2023
    Configuration menu
    Copy the full SHA
    d0a25cc View commit details
    Browse the repository at this point in the history

Commits on Mar 23, 2023

  1. Fix goroutine and channel leak

    The `WatchDeviceChanges` function creates a goroutine that watches for any change notifications coming from the underlying Device. The result of `b.Parse` is sent to the channel `ch` using a blocking send. Because of this, the caller to `WatchDeviceChanges` must continuously empty this channel otherise the goroutine will simply hang on this line, meaning it will never exit and result in a goroutine leak.  So the caller code looks something like this:
    
    ```go
    	ch, err := b.WatchDeviceChanges(ctx)
    	if err != nil {
            ...
        }
    
    	// Make sure to empty the channel
    	go func() {
    		for range ch {}
    	}()
    ```
    
    This brings us onto the second issue: the channel `ch` is only closed when the context `ctx` is done. However, the goroutine can also exit due to `b.propchanged` sending a `nil`, which occurs when `UnwatchDeviceChanges` is called. In this case, `ch` is never closed, which means the caller to `WatchDeviceChanges` that is emptying `ch` will never quit, again resulting in a goroutine and channel leak. Closing the channel using a `defer` at the beginning of the goroutine resolves this issue.
    amrbekhit committed Mar 23, 2023
    Configuration menu
    Copy the full SHA
    80090fa View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    e8088c7 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    615c9b8 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    6abd405 View commit details
    Browse the repository at this point in the history