502 errors with Application Load Balancer Idle Timeout / Apache2 Keep-Alive Timeout

0

I've been getting 502/504 errors since setting up my Application Load Balancer. After reviewing logs with https://repost.aws/knowledge-center/elb-alb-troubleshoot-502-errors, my issue is The target closed the connection with a TCP RST or a TCP FIN while the load balancer had an outstanding request to the target.

I have a 5 second keep-alive on Apache2 to keep memory down, but the website also has some long-running queries that fail unless I increase the load balancer idle timeout beyond 1 minute (currently at 3 minutes).

Is my only option to resolve the 502 errors by increasing my keep-alive timeout to be longer than 3 minutes? It does not seem recommended to increase keep-alive to such a long duration and keep so many connections open.

asked a year ago3259 views
1 Answer
0

Take note Application load balancer IP addresses are allocated dynamically. These IP addresses change when load balancer scales in or scales out. Therefore with the current setup of having External Application load balancer connecting to an Internal application load balancer using target group type IP is not recommended as the target group of the External load balancer can reference Old/ IP addresses of an internal load balancer. When this happens the External load balancer will throw error 502 timeout errors. I would recommend connecting Target/Backend instance directly to the External Application Load Balancer. With this setup you will not need to change the target group IP, every time the IP addresses on internal load balancer are refreshed.

"Keep-Alive" is a header part of the Http Protocol. The Keep-Alive header will allow multiple Http Requests to be send over a single connection instead of using multiple. The "Keep-Alive-Timeout" decides how long theses “Keep-Alive” connections are allowed to stay open. According to Apache documentation , Once a request has been received, the timeout value specified by the Timeout directive applies (The standard Timeout, not the Keep-Alive-Timeout). The Timeout decides the maximum amount of time the server will wait for a client's response, and its default in Apache is 60 seconds.

The Connection Idle Timeout in ALB, which its default value is 60 Seconds as well, works as the “standard” timeout. So If no data has been sent or received by the time that the idle timeout period elapses, the load balancer closes the connection. I strongly recommend you to configure the idle timeout of your application to be larger than the idle timeout configured for the load balancer. In this way, you avoid that the Load Balancer closes a connection before the application.

I’ve also linked an interesting link about HTTP Keep Alive, please have a look at [2].

Should you have any other queries or concerns related to this case, please feel free to write back and I will be happy to clarify your questions!

  1. Apache KeepAlive Timeout https://httpd.apache.org/docs/2.4/mod/core.html#keepalivetimeout
  2. HTTP Keep Alive https://blog.stackpath.com/glossary-keep-alive/
AWS
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions