Skip to content

Commit

Permalink
client: fix Do hangs when configure host client fails (#1514)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Mar 11, 2023
1 parent 9c0e39f commit 7846101
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ func (c *Client) Do(req *Request, resp *Response) error {

if c.ConfigureClient != nil {
if err := c.ConfigureClient(hc); err != nil {
c.mLock.Unlock()
return err
}
}
Expand Down
24 changes: 24 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2734,6 +2734,30 @@ func TestClientTLSHandshakeTimeout(t *testing.T) {
}
}

func TestClientConfigureClientFailed(t *testing.T) {
t.Parallel()

c := &Client{
ConfigureClient: func(hc *HostClient) error {
return fmt.Errorf("failed to configure")
},
}

req := Request{}
req.SetRequestURI("http://example.com")

err := c.Do(&req, &Response{})
if err == nil {
t.Fatal("expected error (failed to configure)")
}

c.ConfigureClient = nil
err = c.Do(&req, &Response{})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
}

func TestHostClientMaxConnWaitTimeoutSuccess(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 7846101

Please sign in to comment.