Request timeout settings for the same domain name are reused (#1558)

* 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>
This commit is contained in:
byte0o
2023-05-14 18:55:02 +08:00
committed by GitHub
parent d2f97fc426
commit 9bc8e480c4
2 changed files with 40 additions and 14 deletions
+8 -14
View File
@@ -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
@@ -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() {
+32
View File
@@ -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
}
@@ -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
@@ -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
@@ -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()