diff --git a/client.go b/client.go index b4e332c22d..e6d9381db6 100644 --- a/client.go +++ b/client.go @@ -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 } } diff --git a/client_test.go b/client_test.go index cf98531448..fc42b2db2a 100644 --- a/client_test.go +++ b/client_test.go @@ -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()