Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCP Load Balancer: 502 Server Error, "failed_to_connect_to_backend"

I have a dockerized Go application running on two GCP instances, everything works fine when using them with their individual external IPs, but when put through the load balancer, they're either slow to answer or it answers a 502 server error. The health checks seems to be ok, so I really don't understand.

In the logs, the error thrown is

failed_to_connect_to_backend

I've already seen other answers on this question, but none of them seems to provide an answer for my case. I cannot modify the way the application is served, so it doesn't seems to be a timeout thing.

like image 332
navelencia Avatar asked Jul 23 '18 08:07

navelencia


People also ask

What is a serverless neg?

A serverless NEG is a backend that points to a Cloud Run, App Engine, Cloud Functions, or API Gateway service. A serverless NEG can represent one of the following: A Cloud Run service or a group of services. A Cloud Functions function or a group of functions.

Is Google load balancer a reverse proxy?

External SSL Proxy Load Balancing is a reverse proxy load balancer that distributes SSL traffic coming from the internet to virtual machine (VM) instances in your Google Cloud VPC network.


1 Answers

To troubleshoot 502 response from the Load Balancer due to "failed_to_connect_to_backend." I would check the followings:

1) Usually, "failed_to_connect_to_backend" error message indicates that the load balancer is failing to connect to backends, investigating URL map rules is also a good point to start. I would also suggest reviewing your Load Balancer's URL map to make sure that Host rules, Path matcher, and Path rules are correctly defined and comply with descriptions in this article.

2) Also check if the backend instances are exhausting their resources, If a backend server is overwhelmed, it will refuse incoming requests, potentially causing the load balancer to give up on it and return the specific 502 error you're experiencing. For Apache, you could use this link and nginx this link. Also, check the output on how many established connections are present at any one time using 'netstat' and watch command.

3) I would also recommend testing again with the HTTP(S) request directly to the instance, request the same URL that reporting 502. You might do this test in another VM instance in your VPC network.

like image 200
Nur Avatar answered Sep 20 '22 05:09

Nur