3

I am using 'request' node.js module (https://github.com/request/request) to send requests to another service. And sometimes it is needed to send request and wait for the response infinitely, because of the slowness of this service to which the request was sent.

It is possible to set 'timeout' property to the request and by this way you will override the default value for read and connection timeout:

timeout - Integer containing the number of milliseconds to wait for a server to send response headers (and start the response body) before aborting the request. Note that if the underlying TCP connection cannot be established, the OS-wide TCP connection timeout will overrule the timeout option (the default in Linux can be anywhere from 20-120 seconds).

But what value we can set to make this timeout infinite?

  • I guess billion would be infinite enough. I really don't think that you would want to wait more than 10 days. – Alexey Ten Feb 22 '17 at 07:39
  • You can control your server timeout. But the client may have its own timeout (such as a browser) which you do not control. – jfriend00 Feb 22 '17 at 07:53
  • Of course, that is an option to set billion. But magic numbers are always look as workarounds. It would be perfect if some official documentation said that setting timeout to 0 is equal to infinite, but it does not say. – Irina Petrushenko Feb 22 '17 at 07:59
  • No timeout is generally not a good design. Any sort of programming mistake that never sends a response will have one or both sides leaking a TCP socket. There are good reasons for timeouts. You may need a different design for communicating back a long running result, either a requestID that the result can be sent back later (either via webSocket or via a future http request asking for the result). – jfriend00 Feb 22 '17 at 08:21
  • Completely agree with you. I already thought about it. But in case nobody wants to rewrite the logic to use requestID, I hope it should be possible to have some "timeout logic". – Irina Petrushenko Feb 22 '17 at 08:27

2 Answers2

1

Set the server.timeout property from 120,000 (default) to 0

FreedomPride
  • 1,098
  • 1
  • 7
  • 30
1

All clients have their own timeout(chrome, Firefox,...) then you must to think that's it's not useful to set a infinite timeout, you must to re-think your problem that's not the good way man

jesusgn90
  • 563
  • 2
  • 12