Skip to content

Commit

Permalink
Merge pull request #23 from uniphil/client-close-after-read-err
Browse files Browse the repository at this point in the history
Close the client connection after a read error
  • Loading branch information
ericvolp12 authored Dec 10, 2024
2 parents 0ab10bd + 5e9ab19 commit 4cb3eef
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"errors"
"fmt"
"log/slog"
"net/http"
Expand Down Expand Up @@ -121,15 +122,17 @@ func (c *Client) ConnectAndRead(ctx context.Context, cursor *int64) error {

c.con = con

var readErr error = nil
if err := c.readLoop(ctx); err != nil {
return fmt.Errorf("read loop failed: %w", err)
readErr = fmt.Errorf("read loop failed: %w", err)
}

var closeErr error = nil
if err := c.con.Close(); err != nil {
return fmt.Errorf("failed to close connection: %w", err)
closeErr = fmt.Errorf("failed to close connection: %w", err)
}

return nil
return errors.Join(readErr, closeErr)
}

func (c *Client) readLoop(ctx context.Context) error {
Expand Down

0 comments on commit 4cb3eef

Please sign in to comment.