Infinite timeout for reverse proxy in Apache

I run a tornado for Apache. I created a proxy server.

ProxyRequests On ProxyPass /chat/ http://localhost:8888/chat/ 

This code works fine and passes all my tornado requests and returns a response to the client.

Now I use a tornado for a long survey. Some of the requests that end in a short period of time say in less than 1 minute, this reverse proxy works fine. But some long polling requests give a 502 proxy error. The reason for this proxy error is that Apache can run a long polling request for as little as one minute (by default). It closes the request and therefore a proxy error is received.

Now I changed the directive to

 ProxyRequests On ProxyPass /chat/ http://localhost:8888/chat/ timeout=12000 

ie I changed the default timeout to 12000 seconds.

This currently works for me. Boo is not the best solution to the problem. Ideally, long polling requests may exceed the specified timeout. So my questions are:

  • How to make the timeout endless? those. the request is never closed by Apache.
  • Also comment: is tornado performance degraded by going through Apache as a proxy?
+8
tornado apache reverse-proxy long-polling
source share
1 answer

I ran into a similar problem with Nginx and solved it just like you did. But I changed the timeout to 1 day, because in my case it was big enough.

I think you cannot end this. The rationale for this is that Apache (or any proxy server in this regard) must maintain its performance, which obviously cannot if it should contain outdated or inactive connections. You would prefer to use a proxy server with more proxy connections than inactive ones.

Therefore, there is no way to disable ProxyTimeout in Apache or even in Nginx (configured using proxy_read_timeout). Therefore, if your proxy server does not send any response during the timeout, then either your application server will respond for too long, or something is wrong with your application server, or the client will not request a response. In the first case, you can make safe estimates to set the appropriate timeout. In the second case, you need to fix your application server. And in the third case, you must gracefully handle the situation on the client and, if necessary, reconnect.

Turning to your second question, there should be no difference other than the delay between your Apache and your Tornado server. You can very well expose your Tornado server directly to the world, but it will be associated with several problems: 1. More work ops - make sure that the Tornado process always works and works. 2. Simplification and load balancing will become more complex. 3. Worst security since you wrote this code instead of thousands of experts. Therefore, you should not think about starting this server as root each. But you can still safely do the same with Apache or Nginx.

Of course, the above problems are solvable, but why solve the already solved problem. :)

+1
source share

All Articles