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?
Set the server.timeout property from 120,000 (default) to 0
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
Related
I’m writing a HTTP/1.1 client that will be used against a variety of servers.
How can I decide a reasonable default keep-alive timeout value, as in, how long the client should keep an unused connection open before closing? Any value I think of seems extremely arbitrary.
First note that that with HTTP keep alive both client and server can close an idle connection (i.e. no outstanding response, no unfinished request) at any time. This means especially that the client cannot make the server keep the connection open by enforcing some timeout, all what a client-side timeout does is limit how long the client will try to keep the connection open. The server might close the connection even before this client-side timeout is reached.
Based on this there is no generic good value for the timeout but there actually does not need to be one. The timeout is essentially used to limit resources, i.e. how much idle connections will be open at the same time. If your specific use case will never visit the same site again anyway then using HTTP keep-alive would just be a waste of resources. If instead you don't know your specific usage pattern you could just place a limit on the number of open connections, i.e. close the longest unused connection if the limit is reached and a new connection is needed. It might make sense to have some upper limit timeout of 10..15 minutes anyway since usually after this time firewalls and NAT routers in between will have abandoned the connection state so the idle connection will no longer work for new requests anyway.
But in any case you also need to be sure that you detect if the server closes a connection and then discard this connection from the list of reusable connections. And if you use HTTP keep-alive you also need to be aware that the server might close the connection in the very moment you are trying to send a new request on an existing connection, i.e. you need to retry this request then on a newly created connection.
I run sanic application and it raises an exception every several seconds even without any request coming in.
sanic.exceptions.RequestTimeout: Request Timeout
How to fix the issue?
I would point you towards the documentation so that you understand what you are doing and why you are receiving that exception. Just blindly changing KEEP_ALIVE to False may not be what you want.
The KEEP_ALIVE config variable is set to True in Sanic by default. If you don’t need this feature in your application, set it to False to cause all client connections to close immediately after a response is sent, regardless of the Keep-Alive header on the request.
The amount of time the server holds the TCP connection open is decided by the server itself. In Sanic, that value is configured using the KEEP_ALIVE_TIMEOUT value. By default, it is set to 5 seconds, this is the same default setting as the Apache HTTP server and is a good balance between allowing enough time for the client to send a new request, and not holding open too many connections at once. Do not exceed 75 seconds unless you know your clients are using a browser which supports TCP connections held open for that long.
The issue comes from the fact that the connection remains alive. Adding following configuration seems to have fixed my issue
from sanic.config import Config
Config.KEEP_ALIVE = False
Incase of MessageTimeoutException, the connection is closed. I don't want to close the connection incase of MessageTimeoutException as I need to send retry messages through the same outbound channel.
To keep this connection alive, I want to set the timeout to infinity. I tried clientFactory.setSoTimeout(-1), but it didn't work. Even I tried gateway.setRemoteTimeout(-1) as well.
Could you please help, how can I set the timeout to infinity?
I have set gateway.setRequestTimeout(10000) and for timeout I get MessageTimeoutException with text as
"Timed out waiting for response" error, where as I should get "Timed out waiting for connection". Please suggest.
You can set the remote timeout to Long.MAX_VALUE which is effectively infinity. This will wait forever (unless you set the socket timeout on the connection factory). I would not advise doing that; choose a more reasonable timeout.
as I need to send retry messages through the same outbound channel
You can't do that; we have to close the socket because we lose any way to correlate the responses - we might get a response for the first message after you send the second. Once we time out, that socket has to be considered "dirty" so we close it.
The gateway is Strictly for request/response messaging. If you want to use arbitrary peer-to-peer messaging you need to use a pair of channel adapters instead.
I have a web application using warp and while trying to query some large-ish using curl I noticed the connection get shutdown exactly after 1 minute transfer. I increased curl's own timeout but this did not changed anything so I assume this is set on the server side.
Is this actually the case there is a 60s timeout on sending response in warp, and if yes, how can I control it?
I'm using Socket.io on a project and would use XHR polling, but I have a limit of 6 concurrent connections. Therefore, after opening 5 tabs, Socket.io starts to hang.
If I set the polling duration to 0 seconds (20 is the default), the limit no longer affects the application but Firebug shows that there's a request every second.
If I use a 0 second limit, how this affect my server and users?
When you set a duration, you are using XHR long-polling. This duration instructs the server on how long to keep a HTTP request open when it does not have any data to send. If the server does have data to send, the data is sent instantly and the connection is closed. The client then creates a new connection and the cycle continues.
When you set the duration to zero, you are effectively telling the server to use short-polling, which if the client asks the server for data, the server will instantly respond with an empty response, or with the data.
The influences that short-polling will have on the client and server are that the client will not receive messages instantly as long-polling would allow, but it consumes less resources because the HTTP request is not kept open. This also means that you probably won't hit your concurrent connection limit, because the connections end immediately.