node.jsubuntuserverpm2http-status-code-503

What could be the reason for the status code 503 Service Unavailable


I am running an Ubuntu server (DigitalOcean droplet) with 2 services. React (Create React App) frontend in PORT 3000 and Node.js backend/API in PORT 8765 with PM2(pm2.keymetrics.io).

Screenshot of PM2 running 2 services

The ports are open (3000 and 8765). I checked.

lsof command showing the open ports

Problem: When the frontend app (in my browser) tries to access the backend it returns the '503 Service Unavailable' status code.

Screeshot of the browser developer tools showing 503

Question: What could be the reason? Can you suggest any steps to try?

Note: It worked fine during the past few weeks. (I used to pull the new changes from the Bitbucket) But today I got this issue.

What I have tried so far


Solution

  • I called the backend (using the frontend) multiple times and observed the running processes with the Ubuntu 'top' utility. See the below screenshot.

    enter image description here

    I noted that the process id for the backend node.js application process is 12225. And this process is repeatedly called even though '503 Service Unavailable' is returned.

    It turned out that the backend application code returns this status code programmatically (with a try-catch block, whenever the error occurs)

    try{
     ...
    }
    catch (e) {
     res.send(503, ...)
    }
    

    I struggled this with for a few days. Hope this will help someone.

    (with this finding the new problem is why the particular error happens on a particular server only. It works fine on EC2 instance. I think it is a different question.)