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

前端 未结 3 1401
后悔当初
后悔当初 2021-02-19 02:08

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).

Bu

相关标签:
3条回答
  • 2021-02-19 02:41

    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

    0 讨论(0)
  • 2021-02-19 02:48

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

    0 讨论(0)
  • 2021-02-19 03:02

    No. There is no default timeout.

    Node.js uses Socket under the hood of http request and socket does not have the timeout by default.

    Use the {timeout: XX} parameter of http.request to configure a proper request timeout.

    0 讨论(0)
提交回复
热议问题