got: Requests with timeout always takes longer than 6 seconds
EXPECTED
- Set
timeout: 100
in option, the request should failed no too much longer than100ms300ms (with 2 retries by default)
CURRENT BEHAVIOR
- It takes longer than 6s to failed on ‘ETIMEOUT’
REPRODUCE
https://runkit.com/amio/5b5873387b9d1e0011ef8f77
- https://untitled-qvjzo3otxk19.runkit.sh/
{ status: 'OK', timespan: 377 }
✔ - https://untitled-qvjzo3otxk19.runkit.sh/2000
{ status: 'OK', timespan: 389 }
✔ - https://untitled-qvjzo3otxk19.runkit.sh/100
{ "status": "Timeout awaiting 'request' for 200ms", "timespan": 6397 }
✘
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 23 (6 by maintainers)
@amio Sorry for late response, but I just recalled this:
The
retry
function delays the next request by((2 ** (iteration - 1)) * 1000)
.@sindresorhus What about making a
retry.delay
option?@sindresorhus Maybe we should expose the retry delay?
If I’ve understand the code correctly this happens because of how the default retry delay is calculated: https://github.com/sindresorhus/got/blob/master/source/normalize-arguments.js#L259.
So your request times out after 300ms, then it waits
((1 << 1) * 1000) + Math.random() * 100;
so ≃ 2000ms, then it times out after 300ms and then waits((1 << 2) * 1000) + Math.random() * 100;
which is ≃ 4000ms. In total around 6600ms.If you want a lower wait before it retries you would have to send in a function to the
retries
argument.@szmarczak I guess it could be useful, but then we need to clearly document that the response may be empty depending on when the timeout occurred.
@szmarczak Sure, I’ll take on this later 😄
Failing test docs: https://github.com/avajs/ava#failing-tests