-
-
Notifications
You must be signed in to change notification settings - Fork 772
Description
When creating a resty client using .SetTimeout(100 * time.Millisecond) and sending a GET request. the response returns context deadline exceeded error as if it took more than 100 ms but it didn't, the response takes around 60 milliseconds.
However, if I don't specify any timeout merely by not using .SetTimeout() function it works as expected and resp.Time() shows that response took 60 ms.
var client = resty.New().SetBaseURL("https://checkip.amazonaws.com").SetTimeout(100 * time.Millisecond)
var counter int
func main() {
app := fiber.New()
app.Get("/", func(c *fiber.Ctx) error {
counter++
resp, err := client.R().Get("/")
if err != nil {
color.Red("Error Response #%d took: %v", counter, resp.Time())
} else {
color.Blue("Success Response #%d took: %v", counter, resp.Time())
}
return nil
})
app.Listen(":3000")
}-
Scenario: Sending 4 requests one after another.
-
Expected behavior: The first request to take around 300 ms and log error, and the remaining 3 requests to take around 60 ms and log success.
-
Actual Behaviour: All 4 requests result in an error of
context deadline exceededeven the ones that didn't took more than 100 ms.
var client = resty.New().SetBaseURL("https://checkip.amazonaws.com").SetTimeout(100 * time.Millisecond)So sending requests with the client above, using the SetTimeout option, results in resp.Time() to return 100 ms no matter the actual response time and end up returning an error:

But sending requests without using SetTimeout option results in resp.Time() to show that it took around 60 ms
var client = resty.New().SetBaseURL("https://checkip.amazonaws.com")Disclaimer: I am not sure if this behaviour is caused by net/http package. I've tried to read the source code of both net/http and resty but couldn't identify if there is a problem.
