-
Notifications
You must be signed in to change notification settings - Fork 124
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
feat: timeout option #201
feat: timeout option #201
Conversation
@ibigbug, thanks for your PR! By analyzing the annotation information on this pull request, we identified @fengmk2, @dead-horse and @xingrz to be potential reviewers |
can set connect timeout and response timeout seperately: timeout: 3000, timeout: [1000, 3000] for connecting timeout 3s and response timeout 5s. caution: will break old timeout config?
start timer after req sent in case socket full won't throw.
Current coverage is 98.33% (diff: 100%)@@ master #201 diff @@
==========================================
Files 1 1
Lines 392 421 +29
Methods 31 36 +5
Messages 0 0
Branches 114 114
==========================================
+ Hits 385 414 +29
Misses 7 7
Partials 0 0
|
@@ -129,7 +129,7 @@ httpclient.request('http://nodejs.org', function (err, body) { | |||
- ***dataType*** String - Type of response data. Could be `text` or `json`. If it's `text`, the `callback`ed `data` would be a String. If it's `json`, the `data` of callback would be a parsed JSON Object. Default `callback`ed `data` would be a `Buffer`. | |||
- **fixJSONCtlChars** Boolean - Fix the control characters (U+0000 through U+001F) before JSON parse response. Default is `false`. | |||
- ***headers*** Object - Request headers. | |||
- ***timeout*** Number - Request timeout in milliseconds. Defaults to `exports.TIMEOUT`. Include remote server connecting timeout and response timeout. When timeout happen, will return `ConnectionTimeout` or `ResponseTimeout`. | |||
- ***timeout*** Number | Array - Request timeout in milliseconds for connecting phase and response receiving phase. Defaults to `exports.TIMEOUT`, both are 5s. You can use `timeout: 5000` to tell urllib use same timeout on two phase or set them seperately such as `timeout: [3000, 5000]`, which will set connecting timeout to 3s and response 5s. |
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.
感觉变化了,原来是 5s 包含2个过程,现在变成了每个过程 5s。不过也还好。
57849c5
to
1a73782
Compare
还是 WIP? |
我看下测试 |
@@ -630,45 +640,78 @@ exports.requestWithCallback = function (url, args, callback) { | |||
}); | |||
} | |||
|
|||
var connectTimeout, responseTimeout; | |||
if (Array.isArray(args.timeout)) { | |||
connectTimeout = ms(args.timeout[0]); |
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.
这里不对,不需要再使用 ms parse 一次的,这里的 timeout 只支持 number 格式,不支持字符串的。
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.
额,如果传了 ['3s', '5s']
进来还是可以的吧 ?
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.
不支持,原来就不支持这种格式。
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.
现在不是支持两种么,一种是原来的指传一个时间,现在可以传一个或两个
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.
但是timeout也是number,不是string啊
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.
额,明白了。ms 只是在内部处理用的。
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.
好吧,原来也有这个逻辑。
__err.name = errorName; | ||
__err.requestId = reqId; | ||
debug('connectTimer boom!!!!'); | ||
debug('Request#%d %s %s: %s, connected: %s', reqId, url, __err.name, msg, connected); |
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.
2个 debug 合并在一起吧
clearTimeout(timer); | ||
timer = null; | ||
} | ||
cancelResponseTimer(); | ||
// should clean up headers.Host on `location: http://other-domain/url` |
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.
看来原来的实现由 bug,MaxRedirectError 和 FollowRedirectError 的逻辑也得cancelResponseTimer
+1 |
2.12.0 |
can set connect timeout and response timeout seperately.