aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorGravatar Igor Menshenin <38577106+iv-menshenin@users.noreply.github.com> 2023-03-03 23:25:39 +0300
committerGravatar GitHub <noreply@github.com> 2023-03-03 21:25:39 +0100
commit74a050705b5a66541add862084aacf292bf6e7ce (patch)
treeade4ad821b452fcda70691580922a1e494cab54a /client.go
parentBump golang.org/x/crypto from 0.0.0-20220214200702-86341886e292 to 0.1.0 (#1508) (diff)
downloadfasthttp-74a050705b5a66541add862084aacf292bf6e7ce.tar.gz
fasthttp-74a050705b5a66541add862084aacf292bf6e7ce.tar.bz2
fasthttp-74a050705b5a66541add862084aacf292bf6e7ce.zip
Immediately return ErrTimeout if deadline is already reached. (#1497)
* fix: Immediately return ErrTimeout if deadline is already reached. * test: Added tests for negative timeout --------- Co-authored-by: Igor Menshenin <igor@native.rent>
Diffstat (limited to 'client.go')
-rw-r--r--client.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/client.go b/client.go
index 4aaaee7..93dd1f6 100644
--- a/client.go
+++ b/client.go
@@ -374,6 +374,7 @@ func (c *Client) Post(dst []byte, url string, postArgs *Args) (statusCode int, b
//
// ErrTimeout is returned if the response wasn't returned during
// the given timeout.
+// Immediately returns ErrTimeout if timeout value is negative.
//
// ErrNoFreeConns is returned if all Client.MaxConnsPerHost connections
// to the requested host are busy.
@@ -387,6 +388,9 @@ func (c *Client) Post(dst []byte, url string, postArgs *Args) (statusCode int, b
// try setting a ReadTimeout.
func (c *Client) DoTimeout(req *Request, resp *Response, timeout time.Duration) error {
req.timeout = timeout
+ if req.timeout < 0 {
+ return ErrTimeout
+ }
return c.Do(req, resp)
}
@@ -407,6 +411,7 @@ func (c *Client) DoTimeout(req *Request, resp *Response, timeout time.Duration)
//
// ErrTimeout is returned if the response wasn't returned until
// the given deadline.
+// Immediately returns ErrTimeout if the deadline has already been reached.
//
// ErrNoFreeConns is returned if all Client.MaxConnsPerHost connections
// to the requested host are busy.
@@ -415,6 +420,9 @@ func (c *Client) DoTimeout(req *Request, resp *Response, timeout time.Duration)
// and AcquireResponse in performance-critical code.
func (c *Client) DoDeadline(req *Request, resp *Response, deadline time.Time) error {
req.timeout = time.Until(deadline)
+ if req.timeout < 0 {
+ return ErrTimeout
+ }
return c.Do(req, resp)
}
@@ -1139,6 +1147,7 @@ func ReleaseResponse(resp *Response) {
//
// ErrTimeout is returned if the response wasn't returned during
// the given timeout.
+// Immediately returns ErrTimeout if timeout value is negative.
//
// ErrNoFreeConns is returned if all HostClient.MaxConns connections
// to the host are busy.
@@ -1152,6 +1161,9 @@ func ReleaseResponse(resp *Response) {
// try setting a ReadTimeout.
func (c *HostClient) DoTimeout(req *Request, resp *Response, timeout time.Duration) error {
req.timeout = timeout
+ if req.timeout < 0 {
+ return ErrTimeout
+ }
return c.Do(req, resp)
}
@@ -1167,6 +1179,7 @@ func (c *HostClient) DoTimeout(req *Request, resp *Response, timeout time.Durati
//
// ErrTimeout is returned if the response wasn't returned until
// the given deadline.
+// Immediately returns ErrTimeout if the deadline has already been reached.
//
// ErrNoFreeConns is returned if all HostClient.MaxConns connections
// to the host are busy.
@@ -1175,6 +1188,9 @@ func (c *HostClient) DoTimeout(req *Request, resp *Response, timeout time.Durati
// and AcquireResponse in performance-critical code.
func (c *HostClient) DoDeadline(req *Request, resp *Response, deadline time.Time) error {
req.timeout = time.Until(deadline)
+ if req.timeout < 0 {
+ return ErrTimeout
+ }
return c.Do(req, resp)
}