diff --git a/go.mod b/go.mod index 36b0701..03a7ed8 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ require ( github.com/arduino/go-properties-orderedmap v1.6.0 github.com/arduino/pluggable-discovery-protocol-handler/v2 v2.0.1 github.com/davecgh/go-spew v1.1.1 // indirect - github.com/s-urbaniak/uevent v1.0.0 + github.com/s-urbaniak/uevent v1.0.1 go.bug.st/serial v1.3.1 golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069 ) diff --git a/go.sum b/go.sum index 266464d..d4eaf08 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/s-urbaniak/uevent v1.0.0 h1:y1e40TmDfCU0l1o/MBpimGJgo2UzTTqBl/0GF6vx/io= -github.com/s-urbaniak/uevent v1.0.0/go.mod h1:h83SVc1NQj/EubPaK4hWyiG217xLYr+fS+Jf10COrG0= +github.com/s-urbaniak/uevent v1.0.1 h1:Zy6g16gR1m6iRB+scDtyExP9KRYnuSdTWOYhBE5O620= +github.com/s-urbaniak/uevent v1.0.1/go.mod h1:h83SVc1NQj/EubPaK4hWyiG217xLYr+fS+Jf10COrG0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= diff --git a/sync/sync_linux.go b/sync/sync_linux.go index f99c359..908511f 100644 --- a/sync/sync_linux.go +++ b/sync/sync_linux.go @@ -19,6 +19,7 @@ package sync import ( "fmt" + "io" discovery "github.com/arduino/pluggable-discovery-protocol-handler/v2" "github.com/s-urbaniak/uevent" @@ -49,12 +50,6 @@ func Start(eventCB discovery.EventCallback, errorCB discovery.ErrorCallback) (ch // Run synchronous event emitter go func() { - defer func() { - recover() - // This recovers from "bufio: reader returned negative count from Read" panic - // when the underlying stream is closed - }() - // Output initial port state for _, port := range current { eventCB("add", toDiscoveryPort(port)) @@ -63,7 +58,11 @@ func Start(eventCB discovery.EventCallback, errorCB discovery.ErrorCallback) (ch dec := uevent.NewDecoder(syncReader) for { evt, err := dec.Decode() - if err != nil { + if err == io.EOF { + // The underlying syncReader has been closed + // so there's nothing else to read + return + } else if err != nil { errorCB(fmt.Sprintf("Error decoding serial event: %s", err)) return }