Node.js Service Failing to Deploy with SIGTERM Error (Health Check Timeout)

vishrut28
FREE

3 months ago

Hello,

My Node.js application is stuck in a deployment loop and consistently fails with a SIGTERM error, indicating a health check timeout. I have already taken all the standard steps to resolve this, but the issue persists.

Here is what I have already done:

  1. The backend is a standard Node.js/Express app with a PostgreSQL database.

  2. The Start Command and Root Directory (./backend) are set correctly.

  3. I refactored my server.js to start the Express server immediately and initialize the database connection after the server is listening, specifically to pass the health check.

  4. I have even added a dedicated /health endpoint and configured it in the service settings.

  5. All environment variables, including DATABASE_URL and GOOGLE_CREDENTIALS, have been meticulously verified.

  6. I have deleted and recreated the service multiple times, but the SIGTERM error continues on every new deployment.

The application runs perfectly, but it seems to be failing to become healthy in the Railway environment. Could you please check the internal platform logs for my service to see why it is being terminated?

Project Name:superb-lightService Name:exemplary-appreciation

Thank you.

$10 Bounty

9 Replies

Railway
BOT

3 months ago


3 months ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open brody 3 months ago


clashing
HOBBY

3 months ago

Hi @vishrut28, most probably in your server file, you might have declared a pre-configured port number, which Railway addresses as Magic/Target Ports. If this is the case, then you have to follow these steps:

a. Before deploying the service, add the PORT variable and use the port number that you are using in the server file.

b. In the healthcheck path setting, you can use /health or health (or whatever endpoint that you are using to do the healthcheck). The slash is not important

I did that on my Express server, and it was a success

The endpoint for your reference is:

app.get("/health", async (req, res) => {
  res.status(200).send({
    success: true,
  });
});

Furthermore, you can refer to this doc: https://docs.railway.com/guides/healthchecks#configure-the-healthcheck-port


clashing

Hi @vishrut28, most probably in your server file, you might have declared a pre-configured port number, which Railway addresses as Magic/Target Ports. If this is the case, then you have to follow these steps:a. Before deploying the service, add the PORT variable and use the port number that you are using in the server file.b. In the healthcheck path setting, you can use /health or health (or whatever endpoint that you are using to do the healthcheck). The slash is not importantI did that on my Express server, and it was a successThe endpoint for your reference is:app.get("/health", async (req, res) => { res.status(200).send({ success: true, }); });Furthermore, you can refer to this doc: https://docs.railway.com/guides/healthchecks#configure-the-healthcheck-port

clashing
HOBBY

3 months ago

Your current build-logs might be looking like this:

This is because of the fact that the PORT is not added as a variable for the Target Port

Do let me know, if you face any other issue


clashing

Your current build-logs might be looking like this:This is because of the fact that the PORT is not added as a variable for the Target PortDo let me know, if you face any other issue

vishrut28
FREE

3 months ago

Thanks mate for the help!
The thing is, i tried this way, but still getting the same old error


vishrut28

Thanks mate for the help!The thing is, i tried this way, but still getting the same old error

clashing
HOBBY

3 months ago

Can you please post the screenshot of build-logs, and one for your PORT environment variable, along with your app.listen code from express file.

Btw, we can also use "/" as the healthcheckup endpoint.


clashing

Can you please post the screenshot of build-logs, and one for your PORT environment variable, along with your app.listen code from express file. Btw, we can also use "/" as the healthcheckup endpoint.

clashing
HOBBY

3 months ago

And also please provide the healthcheckup endpoint that you are using. Surely, we will resolve the issue


clashing
HOBBY

3 months ago

Any update, @vishrut28?

You can also check your healthcheckup timeout constant, by default it is 300seconds, if your healthcheckup endpoint do not return 200, then it fails, and send SIGKILL, which is exactly what is happening with you.

Can you please provide the screenshots that I asked earlier?


clashing
HOBBY

3 months ago

Any update, @vishrut28?


papakrlo
FREE

2 months ago

Hey, something that clicked for me is that the "Stopping Container" and SIGTERM logs that appear after a new deployment refer to the termination of the previous deployment's container, not the new one. Not sure if this is exactly what was happening to you but thought I'd mention this based on my experience.