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

vishrut28
FREE

11 days 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

8 Replies


10 days 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 10 days ago


clashing
FREETop 1% Contributor

10 days 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
FREETop 1% Contributor

10 days 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

10 days 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
FREETop 1% Contributor

10 days 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
FREETop 1% Contributor

10 days ago

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


clashing
FREETop 1% Contributor

9 days 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
FREETop 1% Contributor

5 days ago

Any update, @vishrut28?


Node.js Service Failing to Deploy with SIGTERM Error (Health Check Timeout) - Railway Help Station