Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a default timeout in Node.js for http.request?

Tags:

node.js

In Node.js there is a default timeout for a server (for an incoming HTTP request) at 120000ms (2 minutes) (see HTTP's server.timeout documentation).

But if I want to do an HTTP request in Node.js (using http.request), looking at the documentation, I only find a function request.setTimeout() to set the timeout manually.

Anyone know if there is a default timeout for HTTP requests in Node.js? Or does Node.js try to send the HTTP request with no end?

like image 392
mdunisch Avatar asked May 26 '14 17:05

mdunisch


People also ask

What is the default timeout for Node JS?

In Node. js, default server timeout is 0 milliseconds for the latest version and 2min i.e. (120000 milliseconds) for the older version.

What is the default timeout for HTTP request?

The default value is 60 seconds. If the value of this stanza entry is set to 0 (or not set), connection timeouts between data fragments are governed instead by the client-connect-timeout stanza entry. The exception to this rule occurs for responses returned over HTTP (TCP).

What is request timeout in NodeJS?

By default, NodeJS has a timeout value of 120 seconds. Sometimes you may need to increase request timeout in NodeJS to process long running requests.

Does HTTP have a timeout?

A Request-Timeout header is defined for Hypertext Transfer Protocol (HTTP). This end-to-end header informs an origin server and any intermediaries of the maximum time that a client will await a response to its request. A server can use this header to ensure that a timely response is generated.


2 Answers

You want to set the server.timeout property (it defaults to 120,000, as you've found).


Update: Node.js 13 has removed the default timeout:

  • https://nodejs.org/api/http.html#servertimeout
  • https://github.com/nodejs/node/pull/27558
like image 130
SomeKittens Avatar answered Sep 21 '22 11:09

SomeKittens


I was also interested in this. By reading the code, Node.js uses Socket under the hood of http request (naturally). (The source link below is referring v8.8.0 at the point when I'm writing this)

https://github.com/nodejs/node/blob/master/lib/_http_outgoing.js

And Socket does not have the timeout by default by this document

https://nodejs.org/dist/latest-v6.x/docs/api/net.html#net_socket_settimeout_timeout_callback

And the source tells the same.

https://github.com/nodejs/node/blob/master/lib/net.js

like image 43
beatak Avatar answered Sep 18 '22 11:09

beatak