Nodejs-http.request If there is a timeout

Source: Internet
Author: User

Not by default.

So, what is Req.settimeout (msec, callback) for?

It means that the socket msec is not active after executing callback and does not help you close the connection.

Like a stopwatch, every time you receive data, start from the beginning, metaphorically: "I haven't heard from you for a while."

Hint: The client is not self-contained timeout (need to implement), the server has, the following summarizes the HTTP module in node timeout.

Four timeouts for HTTP (both of which are service-side)
1. Default 2 minutes
2. server.timeout = 120000;
3. Res.on (' timeout ', callback)
4. Req.settimeout (Msecs, callback)

They differ from the following

In the case of HTTP default timeout (2 minutes), if this request is
Up, i.e. no res.end (), then the server triggers req.aborted req.close
Res.close event, close the connection.

However, if Res.on (' timeout ', callback) is registered, after 2 minutes, HTTP executes a timeout callback function, and nothing else is done.

If Req.settimeout is registered (msecs,
callback), then HTTP executes the callback function after the Msecs timeout, and nothing else is done.

If Res.on (' timeout ', callback) and Req.settimeout (Msecs, callback) are registered at the same time, the two callback functions are executed separately, and nothing else is done.

If you only set a smaller server.timeout variable, the timeout behavior is the same as the default, or it will trigger res.aborted
Req.close Res.close, close the connection-just shorten the time-out.

Note: node version v0.12.0

Nodejs-http.request If there is a timeout

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.