From c3354bf868ed862ba6ad635bf7380e5f35cd0d21 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Thu, 12 Sep 2024 09:21:21 +0100 Subject: [PATCH 1/3] .github/go: add errcheck --- .github/workflows/go.yml | 3 +++ 1 file changed, 3 insertions(+) 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 ./... From 3b6e71e300f3726c16861cf46959de420a606834 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Thu, 12 Sep 2024 09:25:57 +0100 Subject: [PATCH 2/3] event/event: return errors from conn.SetReadDeadline --- event/event.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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()) } } From e25cb6edac17066b20d3f5641a18a4e9953cab2e Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Thu, 12 Sep 2024 09:27:49 +0100 Subject: [PATCH 3/3] request: return error in write.Flush call --- request.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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)