1

So I have been running my front end on the server for a few weeks now(angular Server Side rendering). I keep running into this issue where the front end goes down to a 502 error. I have to restart the server ever few hours to ensure that it is back up. The traffic is not crazy and everything seems to be fine(in my console logs- no errors etc) until the point it suddenly goes down. the moment I restart the ssr server, it works fine again. I use the universal library that is the standard for server side rendering in Angular. What could be the issue? what do I need to monitor? RAM? CPU? Something else?

Venomoustoad
  • 111
  • 2
  • Is your server talking to another server? Is there a load balancer in between? – A. Darwin Jul 29 '21 at 07:51
  • yes- it talks to another server, my front end and back end are hosted separately. I had not put a load balancer. Currently there are hardly any interaction between the 2 servers (1000 requests a day probably). Is it required? – Venomoustoad Jul 29 '21 at 08:00
  • a load balancer may or may not be required, but that wasn't my point. The point is, HTTP 502 usually happens when one server (the one eventually replying with a 502) has to talk to another server and fails, for some reason. That's why I asked. – A. Darwin Jul 29 '21 at 08:07
  • Check the logs for whatever bit of your stack is returning the 502 error. – Michael Hampton Jul 29 '21 at 14:33

1 Answers1

0

HTTP 502 typically means that one server (the one originating the HTTP 502 response) tried to talk to another server and failed.

You mention that rebooting the "first" server (the one eventually handing out the 502) fixes the issue, which probably means there's some kind of non-persistent problem on that server.

Possible reasons:

  • memory exhaustion: if your frontend server has to spawn a new process or thread to talk to the backend, it may not be able to do this.

Check RAM utilization (free -m, top) and RAM limits, both global (/etc/security/limits.conf) and per process (cat /proc/PID/limits, where PID is the PID of your process).

  • number of open connections: maybe your frontend has a lot of open connections to the backend server, which means at some point it can't open a new one, and restarting closes those connections.

Run ss -tlpnao | grep <backend server IP> (or any other port) and compare the number of connections with the values of sysctl net.ipv4.ip_local_port_range and sysctl net.ipv4.tcp_fin_timeout .

I would also run a tcpdump -nni any host <backend ip> -v to check what's going on from a packet perspective. Do you get a reply? If so, what kind of reply? Or does the frontend simply never get a reply from the backend? This may help you find the root cause.

A. Darwin
  • 427
  • 1
  • 4