Skip to content

Commit 28a7faa

Browse files
authored
Merge pull request #24 from arduino/scerza/gracefully-close
Handle closing of uevent reader gracefully
2 parents f23c44f + 2d0d905 commit 28a7faa

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require (
55
github.com/arduino/go-properties-orderedmap v1.6.0
66
github.com/arduino/pluggable-discovery-protocol-handler/v2 v2.0.1
77
github.com/davecgh/go-spew v1.1.1 // indirect
8-
github.com/s-urbaniak/uevent v1.0.0
8+
github.com/s-urbaniak/uevent v1.0.1
99
go.bug.st/serial v1.3.1
1010
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069
1111
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
1515
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1616
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1717
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
18-
github.com/s-urbaniak/uevent v1.0.0 h1:y1e40TmDfCU0l1o/MBpimGJgo2UzTTqBl/0GF6vx/io=
19-
github.com/s-urbaniak/uevent v1.0.0/go.mod h1:h83SVc1NQj/EubPaK4hWyiG217xLYr+fS+Jf10COrG0=
18+
github.com/s-urbaniak/uevent v1.0.1 h1:Zy6g16gR1m6iRB+scDtyExP9KRYnuSdTWOYhBE5O620=
19+
github.com/s-urbaniak/uevent v1.0.1/go.mod h1:h83SVc1NQj/EubPaK4hWyiG217xLYr+fS+Jf10COrG0=
2020
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2121
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
2222
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=

sync/sync_linux.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package sync
1919

2020
import (
2121
"fmt"
22+
"io"
2223

2324
discovery "github.com/arduino/pluggable-discovery-protocol-handler/v2"
2425
"github.com/s-urbaniak/uevent"
@@ -49,12 +50,6 @@ func Start(eventCB discovery.EventCallback, errorCB discovery.ErrorCallback) (ch
4950

5051
// Run synchronous event emitter
5152
go func() {
52-
defer func() {
53-
recover()
54-
// This recovers from "bufio: reader returned negative count from Read" panic
55-
// when the underlying stream is closed
56-
}()
57-
5853
// Output initial port state
5954
for _, port := range current {
6055
eventCB("add", toDiscoveryPort(port))
@@ -63,7 +58,11 @@ func Start(eventCB discovery.EventCallback, errorCB discovery.ErrorCallback) (ch
6358
dec := uevent.NewDecoder(syncReader)
6459
for {
6560
evt, err := dec.Decode()
66-
if err != nil {
61+
if err == io.EOF {
62+
// The underlying syncReader has been closed
63+
// so there's nothing else to read
64+
return
65+
} else if err != nil {
6766
errorCB(fmt.Sprintf("Error decoding serial event: %s", err))
6867
return
6968
}

0 commit comments

Comments
 (0)