PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, May 14, 2022

[FIXED] What could be the reason for the status code 503 Service Unavailable

 May 14, 2022     http-status-code-503, node.js, pm2, server, ubuntu     No comments   

Issue

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

  • Restart the server. Same error.
  • Change the Backend port from 9000 to 8765
  • Run the same code in a fresh AWS EC2 instance. There it works fine.
  • Force to listen on IPv4 (based on @adel comment) Screenshot using IPv4

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.)



Answered By - Praveen Dias
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing