diff options
author | byte0o <62271264+byte0o@users.noreply.github.com> | 2023-05-14 18:55:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-14 12:55:02 +0200 |
commit | 9bc8e480c444fa6bf54a4cd79091692ceff6011c (patch) | |
tree | ebf00c55ce5622d5c7d99db73b1151837dd26a10 | |
parent | fix the problem: HostClient maybe delete when pendingClientRequests > 0 (#1562) (diff) | |
download | fasthttp-9bc8e480c444fa6bf54a4cd79091692ceff6011c.tar.gz fasthttp-9bc8e480c444fa6bf54a4cd79091692ceff6011c.tar.bz2 fasthttp-9bc8e480c444fa6bf54a4cd79091692ceff6011c.zip |
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>
-rw-r--r-- | client.go | 22 | ||||
-rw-r--r-- | client_test.go | 32 |
2 files changed, 40 insertions, 14 deletions
@@ -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() { diff --git a/client_test.go b/client_test.go index 69f930c..6609e55 100644 --- a/client_test.go +++ b/client_test.go @@ -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() |