---
title: "ALB 504 errors after a deploy: slow target or no connection? | Proofline"
description: "Read TargetConnectionErrorCount and the maximum TargetResponseTime for the new target group in the minutes when HTTPCode_ELB_504_Count rose."
url: https://proofline.sh/learn/alb-504-after-deploy/
---

[Learning center](/learn/)

# ALB 504 errors after a deploy: slow target or no connection?

Read TargetConnectionErrorCount and the maximum TargetResponseTime for the new target group in the minutes when HTTPCode\_ELB\_504\_Count rose. Connection errors mean the load balancer never reached a target; response times at the idle timeout mean a target was reached and did not answer in time.

Network outages The Proofline team November 22, 2026 7 min read

## The signature and its documented causes

After a deploy, `HTTPCode_ELB_504_Count` climbs from zero. That metric counts HTTP 504 responses that originate from the load balancer, so the 504 is the Application Load Balancer's answer, not your application's. A 504 your tasks return counts in `HTTPCode_Target_5XX_Count` instead. [ALB CloudWatch metrics](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-cloudwatch-metrics.html)

AWS's troubleshooting guide lists the causes of a load balancer 504. Two of them account for most deploys:

-   **No connection.** The load balancer failed to establish a connection to the target before the connection timeout of 10 seconds expired.
-   **No response in time.** The load balancer established a connection, and the target did not respond before the idle timeout elapsed.

The guide also lists a network ACL on the target subnet that blocks return traffic to the load balancer nodes on ephemeral ports 1024 to 65535, a target that sends a `Content-Length` header larger than the body it sends, a Lambda target that does not respond in time, and a 10-second TLS handshake timeout to the target. This guide covers only those causes. [Troubleshoot your Application Load Balancers](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-troubleshooting.html)

HTTP 502 and 503 errors while ECS drains old tasks are a separate question, and so are reason codes for targets that fail health checks. Other routing signatures are in [the signature table](/learn/aws-deployment-failure-signatures/).

## Read the idle timeout first

The idle timeout is a load balancer attribute, `idle_timeout.timeout_seconds`, with a valid range of 1 to 4000 seconds and a default of 60. It is the number you compare response times against. Use a read-only profile and replace the uppercase placeholders. [LoadBalancerAttribute](https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_LoadBalancerAttribute.html) · [describe-load-balancer-attributes](https://docs.aws.amazon.com/cli/latest/reference/elbv2/describe-load-balancer-attributes.html)

```
aws elbv2 describe-load-balancer-attributes \
  --profile PROFILE --region REGION --load-balancer-arn LB_ARN \
  --query 'Attributes[?Key==`"idle_timeout.timeout_seconds"`]' \
  --output json --no-cli-pager
```

## Split the 504s with two target group metrics

`HTTPCode_ELB_504_Count` is published per load balancer and per Availability Zone, with no target group dimension, so it can't say which group the failing requests were meant for. Two target group metrics can:

-   `TargetConnectionErrorCount` counts connections that were not successfully established between the load balancer and a target. Failed health check connections don't count toward it.
-   `TargetResponseTime` is the time from when the request left the load balancer until the target started to send response headers. It matches the access log's `target_processing_time`.

Both publish a `LoadBalancer` plus `TargetGroup` dimension set. Read the three metrics at one-minute resolution over the same window, starting before the deploy. AWS's 504 troubleshooting article suggests checking `TargetConnectionErrorCount` for positive values and comparing the maximum `TargetResponseTime` with the idle timeout. [ALB CloudWatch metrics](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-cloudwatch-metrics.html) · [Troubleshoot ALB 504 errors](https://repost.aws/knowledge-center/504-error-alb) · [GetMetricStatistics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricStatistics.html)

```
aws cloudwatch get-metric-statistics \
  --profile PROFILE --region REGION --namespace AWS/ApplicationELB \
  --metric-name HTTPCode_ELB_504_Count \
  --dimensions Name=LoadBalancer,Value=LB_DIMENSION \
  --start-time START --end-time END --period 60 --statistics Sum \
  --query 'sort_by(Datapoints,&Timestamp)[].[Timestamp,Sum]' \
  --output json --no-cli-pager

aws cloudwatch get-metric-statistics \
  --profile PROFILE --region REGION --namespace AWS/ApplicationELB \
  --metric-name TargetConnectionErrorCount \
  --dimensions Name=LoadBalancer,Value=LB_DIMENSION Name=TargetGroup,Value=TG_DIMENSION \
  --start-time START --end-time END --period 60 --statistics Sum \
  --query 'sort_by(Datapoints,&Timestamp)[].[Timestamp,Sum]' \
  --output json --no-cli-pager

aws cloudwatch get-metric-statistics \
  --profile PROFILE --region REGION --namespace AWS/ApplicationELB \
  --metric-name TargetResponseTime \
  --dimensions Name=LoadBalancer,Value=LB_DIMENSION Name=TargetGroup,Value=TG_DIMENSION \
  --start-time START --end-time END --period 60 --statistics Maximum Average \
  --query 'sort_by(Datapoints,&Timestamp)[].[Timestamp,Maximum,Average]' \
  --output json --no-cli-pager
```

`aws cloudwatch list-metrics --namespace AWS/ApplicationELB --metric-name TargetResponseTime` lists the exact dimension values to pass.

## What each result means

| In the 504 minutes | Likely cause | Next check |
| --- | --- | --- |
| `TargetConnectionErrorCount` rises with the 504 count | No connection to a target | Security groups and network ACLs between the load balancer and the new tasks; whether every target is unhealthy |
| Maximum `TargetResponseTime` sits at the idle timeout | A target was reached and answered too slowly | The new revision's slow endpoints; the request paths in the access log |
| Both | Some requests found no target and others timed out; each cause has its own share | Access log entries, one per 504 |
| Neither | A cause the metrics don't separate, such as a short body after `Content-Length` or a TLS handshake timeout | Access log entries for the 504s |

The metrics sum many requests over a minute, so one cause showing does not rule out the other. When both move, count the 504 entries in the access log by cause before fixing either. A connection error with healthy targets in the target group points at the path between the load balancer and the task. AWS's first step for a connection timeout is to connect to the target's private address from inside the network with the health check protocol, and to check whether the target is overloaded. [Troubleshoot your Application Load Balancers](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-troubleshooting.html)

Connection errors can also appear when every target is unhealthy. When fewer targets are healthy than `target_group_health.unhealthy_state_routing.minimum_healthy_targets.count`, which defaults to 1, the load balancer sends traffic to all targets, including unhealthy ones. Requests then reach tasks that can't accept them. [TargetGroupAttribute](https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_TargetGroupAttribute.html)

## Read the access log entries

If access logs were enabled before the deploy, each 504 entry adds detail the metrics lack. `target:port` names the target the request was sent to, so you can match it to old or new tasks. `target_status_code` is `-` when no response came from the target. `target_processing_time` is -1 when the load balancer could not dispatch the request or the target did not respond before the idle timeout. The gap between `request_creation_time` and `time`, when the load balancer sent its response, shows how long each request waited: close to 10 seconds fits the connection timeout, and close to the idle timeout fits a slow target. [ALB access log fields](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html)

## An illustrative fixture: two causes, one alarm

This fixture is fictional. The service `checkout` moves from `checkout:41` to `checkout:42` at 14:00 UTC, behind an Application Load Balancer with the default 60-second idle timeout. `HTTPCode_ELB_504_Count` goes from 0 to about 40 a minute by 14:08.

In the first reading, `TargetConnectionErrorCount` for `checkout-tg` stays at 0, and the maximum `TargetResponseTime` is above 55 seconds in every minute from 14:06, against an average of 0.2. Access log 504s all name `/orders/export` and show about 60 seconds between `request_creation_time` and `time`. `checkout:42` changed the export to build the whole file before it responds. The targets accepted the requests and took longer than the idle timeout. The change belongs in the export handler; raising the idle timeout would only hide it until the files grow.

In the second reading, `TargetConnectionErrorCount` rises from 14:05 to about 40 a minute, tracking the 504 count, and `TargetResponseTime` is normal for requests that got through. `checkout:42`'s deployment runs in new subnets, and the network ACL on those subnets blocks ephemeral return ports. Once the last old task drained at 14:05, every target was unhealthy, and the load balancer routed to all of them. Access log 504s show about 10 seconds per request. The fix is the network ACL, and the release code is not involved.

## Change one setting and confirm on the replacement

Raise the idle timeout only when a request legitimately runs longer than the current value. This command changes the load balancer. [modify-load-balancer-attributes](https://docs.aws.amazon.com/cli/latest/reference/elbv2/modify-load-balancer-attributes.html)

```
# Change: raise the idle timeout to 120 seconds
aws elbv2 modify-load-balancer-attributes \
  --profile PROFILE --region REGION --load-balancer-arn LB_ARN \
  --attributes Key=idle_timeout.timeout_seconds,Value=120 \
  --output json --no-cli-pager
```

After a network or code fix, read the same three metrics again for the new target group. `HTTPCode_ELB_504_Count` should return to zero, which shows up as no data points because the count is reported only when it is nonzero. `TargetConnectionErrorCount` should stay at zero, and the maximum `TargetResponseTime` should sit well below the idle timeout under the same traffic.

## Where the reading stops

The metrics are reported only while requests flow, and the 504 count has no target group dimension, so with several services behind one load balancer you need the target group metrics or access logs to know whose requests failed. The sources used here don't say whether a request that timed out contributes to `TargetResponseTime`, so treat a low maximum as weak evidence and confirm with access logs. A 504 from the load balancer also says nothing about the dependency your task was waiting on; a slow database call and a slow handler look the same here.

If the 504s stop but clients still see the old version, check for [traffic on the wrong target group](/learn/alb-traffic-on-wrong-target-group-after-deploy/). If the new tasks sit behind a Network Load Balancer instead, which returns no HTTP status of its own, read the [security group path for NLB targets](/learn/nlb-targets-unhealthy-security-group/).

## Questions

### How do I tell whether a 504 came from the ALB or from my application?

`HTTPCode_ELB_504_Count` counts 504s the load balancer generated. A 504 your application returns is counted in `HTTPCode_Target_5XX_Count`. If the ELB metric has no data for the minutes in question, the load balancer did not generate those 504s.

### What does TargetConnectionErrorCount mean for 504 errors?

It counts connections the load balancer could not establish with a target. Rising with the 504 count, it points at the path to the targets, such as security groups or network ACLs, or at targets that can't accept connections. It does not count failed health check connections.

### Should I raise the ALB idle timeout to fix 504 errors?

Only if `TargetResponseTime` shows requests that legitimately run past the current idle timeout. A longer idle timeout does not help requests that failed to connect, because the load balancer never reached a target. When connection errors and slow responses appear in the same minutes, read the access log: a 504 entry that waited about 10 seconds fits the connection timeout, while one that waited about the idle timeout is the kind a longer timeout could serve.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [ALB still sends traffic to the old target group after a deploy](/learn/alb-traffic-on-wrong-target-group-after-deploy/)
    
    Deployment failures The Proofline team November 22, 2026 8 min read
    
-   ### [AWS deployment failure signatures: startup, placement, health, routing or scaling](/learn/aws-deployment-failure-signatures/)
    
    Deployment failures The Proofline team November 22, 2026 9 min read
