Skip to content
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

Merged
merged 5 commits into from
Aug 8, 2016
Merged

feat: timeout option #201

merged 5 commits into from
Aug 8, 2016

Conversation

ibigbug
Copy link
Member

@ibigbug ibigbug commented Aug 4, 2016

can set connect timeout and response timeout seperately.

@mention-bot
Copy link

@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.
@codecov-io
Copy link

codecov-io commented Aug 5, 2016

Current coverage is 98.33% (diff: 100%)

Merging #201 into master will increase coverage by 0.12%

@@             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          

Sunburst

Powered by Codecov. Last update d88b63b...037509d

@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉变化了,原来是 5s 包含2个过程,现在变成了每个过程 5s。不过也还好。

@ibigbug ibigbug force-pushed the feat/timeout branch 2 times, most recently from 57849c5 to 1a73782 Compare August 5, 2016 12:44
@ibigbug ibigbug changed the title feat: timeout option WIP: feat: timeout option Aug 5, 2016
@fengmk2
Copy link
Member

fengmk2 commented Aug 8, 2016

还是 WIP?

@ibigbug ibigbug changed the title WIP: feat: timeout option feat: timeout option Aug 8, 2016
@ibigbug
Copy link
Member Author

ibigbug commented Aug 8, 2016

我看下测试

@@ -630,45 +640,78 @@ exports.requestWithCallback = function (url, args, callback) {
});
}

var connectTimeout, responseTimeout;
if (Array.isArray(args.timeout)) {
connectTimeout = ms(args.timeout[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不对,不需要再使用 ms parse 一次的,这里的 timeout 只支持 number 格式,不支持字符串的。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

额,如果传了 ['3s', '5s'] 进来还是可以的吧 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不支持,原来就不支持这种格式。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在不是支持两种么,一种是原来的指传一个时间,现在可以传一个或两个

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

但是timeout也是number,不是string啊

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

额,明白了。ms 只是在内部处理用的。

Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2个 debug 合并在一起吧

@fengmk2 fengmk2 added the feature label Aug 8, 2016
@fengmk2 fengmk2 self-assigned this Aug 8, 2016
clearTimeout(timer);
timer = null;
}
cancelResponseTimer();
// should clean up headers.Host on `location: http://other-domain/url`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看来原来的实现由 bug,MaxRedirectError 和 FollowRedirectError 的逻辑也得cancelResponseTimer

@fengmk2
Copy link
Member

fengmk2 commented Aug 8, 2016

+1

@fengmk2 fengmk2 merged commit dde2eeb into node-modules:master Aug 8, 2016
@ibigbug ibigbug deleted the feat/timeout branch August 8, 2016 12:44
@fengmk2
Copy link
Member

fengmk2 commented Aug 8, 2016

2.12.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants