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?
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:
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).
Run
ss -tlpnao | grep <backend server IP>
(or any other port) and compare the number of connections with the values ofsysctl net.ipv4.ip_local_port_range
andsysctl 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.