-
-
Notifications
You must be signed in to change notification settings - Fork 957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request timeout #308
Request timeout #308
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index.js
Outdated
false; | ||
|
||
if (timeoutDuration) { | ||
timeout = setTimeout(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use p-timeout here instead?
await s.listen(s.port); | ||
}); | ||
|
||
test('timeout option', async t => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the tests tend to take this form:
const err = await t.throws(got(`${s.url}/`, {
timeout: 1,
retries: 0
}));
t.is(err.code, 'ETIMEDOUT');
I'd be in favor of testing this way because:
- it offloads worrying about if it throws to ava.
- consistent style is helpful in reducing complexity.
@floatdrop so should we just name the option gotTimeout? |
@djmadeira nah, |
@floatdrop @alextes addressed comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does timeout
option works with stream mode?
index.js
Outdated
@@ -152,6 +162,7 @@ function asPromise(opts) { | |||
throw new got.HTTPError(statusCode, res.headers, opts); | |||
} | |||
|
|||
clearTimeout(timeout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left over?
index.js
Outdated
|
||
return (requestPromise => timeout ? | ||
pTimeout(requestPromise, timeout, new got.RequestError({message: 'Request timed out', code: 'ETIMEDOUT'}, opts)) : | ||
requestPromise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be more readable. Can you move it (line 111 to 113) out into a separate variable?
readme.md
Outdated
|
||
Option accepts `object` with separate `connect` and `socket` fields for connection and socket inactivity timeouts. | ||
Option accepts `object` with separate `connect`, `socket`, and `request` fields for connection, socket, and entire request timeouts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's not from this change, but Option accepts
object with separate
=> This also accepts an
object with separate
.
@sindresorhus @floatdrop addressed comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! 🌈
Thank you for this contribution. I spent a few hour struggling to find out why I wasn't catching the timeout errors, so I resorted to reading the code. Lo and behold, a fix was merged on v7.0.0 so all I had to do was update my version of got. Thanks, man! =) |
It should have been a major release probably :( |
Fixes #257.
Changes timeout option so that if a number is supplied, that is the timeout for the entire request to be completed; if an object is supplied, the keys
connect
,socket
, andrequest
set connection, socket, and entire request timeouts, respectively.Open questions: