diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ffa1a18..9355d34 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -29,6 +29,9 @@ jobs: - name: Staticcheck run: go run honnef.co/go/tools/cmd/staticcheck@2023.1.7 ./... + - name: Errcheck + run: go run github.com/kisielk/errcheck@v1.7.0 -ignoretests ./ ./event + - name: Build run: go build -v ./... diff --git a/event/event.go b/event/event.go index 69e9f72..4f1fd1f 100644 --- a/event/event.go +++ b/event/event.go @@ -2,6 +2,7 @@ package event import ( "context" + "errors" "fmt" "net" "strings" @@ -95,10 +96,8 @@ func (c *EventClient) Subscribe(ctx context.Context, ev EventHandler, events ... } } -func readWithContext(ctx context.Context, conn net.Conn, buf []byte) (int, error) { +func readWithContext(ctx context.Context, conn net.Conn, buf []byte) (n int, err error) { done := make(chan struct{}) - var n int - var err error // Start a goroutine to perform the read go func() { @@ -111,12 +110,19 @@ func readWithContext(ctx context.Context, conn net.Conn, buf []byte) (int, error return n, err case <-ctx.Done(): // Set a short deadline to unblock the Read() - conn.SetReadDeadline(time.Now()) + err = conn.SetReadDeadline(time.Now()) + if err != nil { + return 0, err + } // Reset read deadline - defer conn.SetReadDeadline(time.Time{}) + defer func() { + if e := conn.SetReadDeadline(time.Time{}); e != nil { + err = errors.Join(err, e) + } + }() // Make sure that the goroutine is done to avoid leaks <-done - return 0, ctx.Err() + return 0, errors.Join(err, ctx.Err()) } } diff --git a/request.go b/request.go index 0a999e5..2f619ec 100644 --- a/request.go +++ b/request.go @@ -278,7 +278,10 @@ func (c *RequestClient) RawRequest(request RawRequest) (response RawResponse, er if err != nil { return nil, fmt.Errorf("error while writing to socket: %w", err) } - writer.Flush() + err = writer.Flush() + if err != nil { + return nil, fmt.Errorf("error while flushing to socket: %w", err) + } // Get the response back rbuf := bytes.NewBuffer(nil)