502 after 5 seconds

Hi Community,

I’ve a serious problem. There’s an api in my webservice (Springboot) which might take a few seconds to respond. When I use domain name through Cloudflare, I get 502 bad gateway after exactly 5 seconds, but when I use my server ip address (bypassing Cloudflare) I get correct response after say 7 seconds. There’s an Nginx in front of my backend webservice as reverse proxy, but it doesn’t cause this problem, because as I said, it works correctly when I use my server’s ip address directly. I know the api is being called and working correctly because I can see the logs of my server.
This is confusing and I need a help asap, because this api is being used by our clients.
Thanks

Have you seen this in a browser? I ask because a 502 can either be due to a Cloudflare error (plaintext error screen) or a host connection error (Cloudflare-branded error screen).

It’s Cloudflare-branded error screen, which means it’s probably not related to Cloudflare but it happens when I use domain name and it doesn’t happen when I use server’s ip address. Totally confusing

I fixed it. The problem was GCP load balancer. When I was calling api directly from server’s ip address, load balancer was not involved and it responds correctly. But when I was using domain name (through Cloudflare), load balancer was used to dispatch api call to different servers. The problem was the load balancer’s timeout value which was set to 3 seconds, which was causing api to fail and returing 502 to Cloudflare.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.