Skip to content

Commit 7846101

Browse files
authored
client: fix Do hangs when configure host client fails (#1514)
1 parent 9c0e39f commit 7846101

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ func (c *Client) Do(req *Request, resp *Response) error {
527527

528528
if c.ConfigureClient != nil {
529529
if err := c.ConfigureClient(hc); err != nil {
530+
c.mLock.Unlock()
530531
return err
531532
}
532533
}

client_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,6 +2734,30 @@ func TestClientTLSHandshakeTimeout(t *testing.T) {
27342734
}
27352735
}
27362736

2737+
func TestClientConfigureClientFailed(t *testing.T) {
2738+
t.Parallel()
2739+
2740+
c := &Client{
2741+
ConfigureClient: func(hc *HostClient) error {
2742+
return fmt.Errorf("failed to configure")
2743+
},
2744+
}
2745+
2746+
req := Request{}
2747+
req.SetRequestURI("http://example.com")
2748+
2749+
err := c.Do(&req, &Response{})
2750+
if err == nil {
2751+
t.Fatal("expected error (failed to configure)")
2752+
}
2753+
2754+
c.ConfigureClient = nil
2755+
err = c.Do(&req, &Response{})
2756+
if err != nil {
2757+
t.Fatalf("unexpected error: %v", err)
2758+
}
2759+
}
2760+
27372761
func TestHostClientMaxConnWaitTimeoutSuccess(t *testing.T) {
27382762
t.Parallel()
27392763

0 commit comments

Comments
 (0)