Lesson 3 of 3 Elastic Load Balancing

Troubleshooting Load Balancer Errors

This lesson explains how the status code, and whether it came from the load balancer or the target, tell you where to look when users receive HTTP errors.

Learning outcomes

After completing this lesson, you will be able to:

  • Separate load balancer errors from target errors with metrics.
  • Identify the causes of ALB 502, 503 and 504 errors.
  • Resolve other common issues such as uneven load.

Load balancer or target?

ALB metrics separate errors generated by the load balancer (HTTPCode_ELB_4XX_Count, HTTPCode_ELB_5XX_Count) from responses returned by targets (HTTPCode_Target_4XX_Count, HTTPCode_Target_5XX_Count). A target 5XX means the application returned the error; an ELB 5XX means the load balancer could not get a valid response. Access logs, stored in S3 when enabled, contain both elb_status_code and target_status_code (a dash when the target did not respond), plus request_processing_time, target_processing_time and response_processing_time. Connection logs record TLS handshake details, and health check logs record each check.

The following diagram shows which side generates each kind of error.

Where ALB error codes come from. HTTPCode_Target metrics count errors the application returned. HTTPCode_ELB metrics count errors the load balancer generated: 502 when a target returned an invalid response or closed the connection, 503 when there are no healthy registered targets, and 504 when a target did not respond within the idle timeout.
Comparing the ELB and Target metrics is the first step in deciding where to look.

Load balancer error codes

The following table lists the ALB-generated errors and their usual causes.

CodeMeaningUsual cause
502 Bad GatewayInvalid response from targetTarget closed the connection, malformed response, Lambda error or response too large, keep-alive timeout on the target shorter than the ALB idle timeout
503 Service UnavailableNo registered healthy targetsEmpty target group or all targets in unused AZs
504 Gateway TimeoutTarget did not respond within the idle timeoutSlow application, idle timeout too short, or security group/NACL dropping traffic to the target
460Client closed connection before the responseClient timeout shorter than the processing time
463X-Forwarded-For header with too many IPsProxy chain misconfiguration
4XX from ELB (400, 403)Malformed request or WAF blockCheck WAF logs for 403
Match the pairs

ALB error codes

Exam skills 2.2.1 · 5.3.2

Match each ALB-generated error with its usual cause.

Log in to try this activity Interactive activities are free with an account.

Other common issues

Several other issues appear regularly. The following list describes them.

  • Uneven load: cross-zone load balancing off on an NLB with unequal targets per AZ, or sticky sessions concentrating users.
  • Client IP missing in application logs: an ALB passes it in the X-Forwarded-For header; NLBs preserve it at the IP level (or with proxy protocol v2).
  • Users logged out after scale-in: sessions stored locally; use ElastiCache or DynamoDB, or stickiness as a short-term fix.
  • Long-running requests cut off: the idle timeout (60 seconds by default) is shorter than the request.
  • Requests fail during deployments: deregistration delay too short for in-flight requests.

60s

Default idle timeout

Troubleshooting scenario

Load balancer symptoms

Exam skills 2.2.1 · 2.1.2

Fix common load balancer problems from their symptoms.

Log in to try this activity Interactive activities are free with an account.
Worked example

Intermittent 502 errors

An ALB reports a small but steady rate of HTTPCode_ELB_502_Count while target 5XX counts are zero. Access logs show the 502 requests have target_status_code of - and very short processing times, and they occur on connections that had been idle for about 5 seconds. The targets run a web server with a keep-alive timeout of 5 seconds, while the ALB's idle timeout is 60 seconds, so the server sometimes closes a connection at the moment the ALB reuses it. Setting the web server's keep-alive timeout above the ALB idle timeout, to 65 seconds, eliminates the errors.

Check yourself

What does a 503 from an Application Load Balancer usually mean?

Show answer

There are no healthy targets in the target group.

Exam Tips

Remember for the exam

  • HTTPCode_ELB_5XX is the load balancer; HTTPCode_Target_5XX is the application.
  • 502: bad or closed target response; 503: no healthy targets; 504: target too slow.
  • Set target keep-alive timeouts longer than the ALB idle timeout.
  • Access logs show elb_status_code, target_status_code and processing times.
  • ALBs pass the client IP in X-Forwarded-For.