Score:1

Angular server side rendering keeps going down to 502 errors

br flag

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?

A. Darwin avatar
my flag
Is your server talking to another server? Is there a load balancer in between?
br flag
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?
A. Darwin avatar
my flag
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.
Michael Hampton avatar
cz flag
Check the logs for whatever bit of your stack is returning the 502 error.
Score:0
my flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.