response_sent_by_backend
- Meaning in Google's guide
- The load balancer relayed the 5xx from the backend
- Where to look
- Your backend's own logs
A Google Cloud load balancer 502 is explained by one log field, statusDetails. Match it to a cause, then fix the firewall, keep-alive or GKE shutdown timing.
A 502 from a Google Cloud external Application Load Balancer is either relayed from your backend or generated by the load balancer, and the Cloud Logging field jsonPayload.statusDetails says which. Values such as failed_to_connect_to_backend or backend_connection_closed_before_data_sent_to_client point to firewall rules, a listening port, or a backend keep-alive shorter than the load balancer's 600 seconds.
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
statusDetails field in the request log is how you tell them apart.response_sent_by_backendfailed_to_pick_backend, failed_to_pick_backend_by_hashfailed_to_connect_to_backendbackend_connection_closed_before_data_sent_to_clientclient --> first-layer GFE --> second-layer GFE --> your backend
| |
generates 5xx for connection sends its own 5xx,
or pick-a-backend problems which is relayed as-is
(statusDetails: response_sent_by_backend)gcloud CLI; I did not run them here, so the syntax is adapted from the Cloud Logging resource type and fields named in the load balancer docs.curl -sS -o /dev/null -w "%{http_code}\n" https://httpbin.org/status/502
# observed: 502gcloud logging read \
'resource.type="http_load_balancer" AND httpRequest.status>=500' \
--limit=200 \
--format='value(jsonPayload.statusDetails)' \
| sort | uniq -c | sort -rn 41 failed_to_connect_to_backend
3 response_sent_by_backendThe counts above show the shape only; they are not from a real project. Your top line tells you which row to read next. If it is response_sent_by_backend, stop reading load balancer docs and debug the application.
failed_to_pick_backend and failed_to_connect_to_backend share the same first suspect: an ingress firewall rule. Google Cloud requires an allow rule for the health check probers, and with none, the implied deny rule blocks the probes and the backends turn unhealthy. For GFE-based external Application Load Balancers the IPv4 probe range in the docs is 35.191.0.0/16, and the guide says to allow all probe ranges for your load balancer type because new probers can appear without notice.Open the probe IP ranges table in the health check concepts page and copy the ranges for your load balancer type and backend type.
The app must be running and listening on the port configured in the backend service. A health check on the wrong port, path or protocol fails the same way.
Look at CPU, memory and connection metrics on the backends. Google lists resource exhaustion as a cause of failed connections.
If failed_to_pick_backend continues while some instance groups are healthy, the guide says failover is limited to a few alternate groups, and to drain the unhealthy groups by setting their capacity to zero.
gcloud compute firewall-rules create fw-allow-health-checks \
--network=NETWORK_NAME \
--action=ALLOW \
--direction=INGRESS \
--source-ranges=35.191.0.0/16 \
--target-tags=allow-health-checks \
--rules=tcp:PORTbackend_connection_closed_before_data_sent_to_client is the keep-alive race, and Google gives specific numbers. Set the HTTP keep-alive timeout on the backend web server to more than the load balancer's 600-second timeout, with a recommended 620 seconds. nginx's documented keepalive_timeout default is 75 seconds, which is well short of that number, so an nginx left at its default needs the change.backend_connection_closed_before_data_sent_to_clientfailed_to_pick_backend appears right after you added or removed a backend serviceretriable_error follows an apply that recreated URL map ruleshttp {
keepalive_timeout 620s;
}On GKE, Google ties the same error to pods that are scaling down or terminating when the load balancer backends are NEGs. The remedy is a longer terminationGracePeriodSeconds so existing connections can close. The guide's formula is Tgrace > TpreStop + Tdrain + Tbuffer, with a preStop sleep that is typically 120 seconds, connection draining typically 60 seconds, and a buffer of 30 to 45 seconds. For standard setups it recommends at least 210 seconds.
spec:
terminationGracePeriodSeconds: 210
containers:
- name: app
lifecycle:
preStop:
exec:
command: ["sleep", "120"]Search crawlers back off from 5xx responses, according to Google's status code guide, and URLs already in the index can fall out if the errors persist. A short burst of failed_to_pick_backend during a configuration change is the documented harmless kind. A persistent failed_to_connect_to_backend is not, and an automation tool that deletes then recreates URL map rules can produce its own 503 window. Prefer in-place updates, as the guide says. See 5xx server errors and Cloud Run 503 for the serverless side.
3 questions people ask next, answered from the sources on this page.
Check jsonPayload.statusDetails in Cloud Logging. response_sent_by_backend means the load balancer relayed a 5xx your backend produced. Any other failure message means the load balancer generated the error.
Google's guide says configuration changes such as adding or removing a backend service can cause a brief period of 502 responses with statusDetails of failed_to_pick_backend, and that this is normal while the change propagates to the GFEs globally.
Greater than the load balancer's 600-second timeout, with 620 seconds recommended. The guide names Apache and nginx as examples of backend web servers to configure.
Run the free audit, then approve the fixes. Every change can be undone.