Skip to content

Commit

Permalink
Request timeout settings for the same domain name are reused (#1558)
Browse files Browse the repository at this point in the history
* Update client.go

fix client http SetReadDeadline/SetWriteDeadline Deadline is reused

* delete Deadline comments  fix test singleEchoConn implement SetWriteDeadline/SetReadDeadline

* fix test SetReadDeadline/SetWriteDeadline none implement

---------

Co-authored-by: gaoping <gaoping1@wps.cn>
  • Loading branch information
byte0o and gaoping authored May 14, 2023
1 parent d2f97fc commit 9bc8e48
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
22 changes: 8 additions & 14 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1387,13 +1387,10 @@ func (c *HostClient) doNonNilReqResp(req *Request, resp *Response) (bool, error)
writeDeadline = tmpWriteDeadline
}
}
if !writeDeadline.IsZero() {
// Set Deadline every time, since golang has fixed the performance issue
// See https://github.com/golang/go/issues/15133#issuecomment-271571395 for details
if err = conn.SetWriteDeadline(writeDeadline); err != nil {
c.closeConn(cc)
return true, err
}

if err = conn.SetWriteDeadline(writeDeadline); err != nil {
c.closeConn(cc)
return true, err
}

resetConnection := false
Expand Down Expand Up @@ -1432,13 +1429,10 @@ func (c *HostClient) doNonNilReqResp(req *Request, resp *Response) (bool, error)
readDeadline = tmpReadDeadline
}
}
if !readDeadline.IsZero() {
// Set Deadline every time, since golang has fixed the performance issue
// See https://github.com/golang/go/issues/15133#issuecomment-271571395 for details
if err = conn.SetReadDeadline(readDeadline); err != nil {
c.closeConn(cc)
return true, err
}

if err = conn.SetReadDeadline(readDeadline); err != nil {
c.closeConn(cc)
return true, err
}

if customSkipBody || req.Header.IsHead() {
Expand Down
32 changes: 32 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,14 @@ func (w *writeErrorConn) RemoteAddr() net.Addr {
return nil
}

func (r *writeErrorConn) SetReadDeadline(_ time.Time) error {
return nil
}

func (r *writeErrorConn) SetWriteDeadline(_ time.Time) error {
return nil
}

type readErrorConn struct {
net.Conn
}
Expand All @@ -2219,6 +2227,14 @@ func (r *readErrorConn) RemoteAddr() net.Addr {
return nil
}

func (r *readErrorConn) SetReadDeadline(_ time.Time) error {
return nil
}

func (r *readErrorConn) SetWriteDeadline(_ time.Time) error {
return nil
}

type singleReadConn struct {
net.Conn
s string
Expand Down Expand Up @@ -2250,6 +2266,14 @@ func (r *singleReadConn) RemoteAddr() net.Addr {
return nil
}

func (r *singleReadConn) SetReadDeadline(_ time.Time) error {
return nil
}

func (r *singleReadConn) SetWriteDeadline(_ time.Time) error {
return nil
}

type singleEchoConn struct {
net.Conn
b []byte
Expand Down Expand Up @@ -2282,6 +2306,14 @@ func (r *singleEchoConn) RemoteAddr() net.Addr {
return nil
}

func (r *singleEchoConn) SetReadDeadline(_ time.Time) error {
return nil
}

func (r *singleEchoConn) SetWriteDeadline(_ time.Time) error {
return nil
}

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

Expand Down

0 comments on commit 9bc8e48

Please sign in to comment.