Healtcheck Not Working
kafkasl
PROOP

a year ago

I can't get the healthcheck setting to work. I have a /health endpoint that currently works in the deployment:

❯ curl -s -w "\n%{http_code}\n" https://shopify-data-pipeline-production.up.railway.app/health

{"status":"ok"}

200

However when I add the health check option the server deployment fails (due to the healtcheck). I have tried the following values for the setting without success:

What is the correct way to set this up?

Solved$20 Bounty

Pinned Solution

a year ago

(When I say None in this response I mean null, however that applies in Dockerfile or Python.)

Railway's healthcheck uses the PORT variable. It doesn't look at anything else, and it uses the internal IP. Try making a variable named PORT and setting it to 5001, as well as changing your host in that Dockerfile to be None. Changing your host to that ensures that Railway can access it over IPv6, and adding the port variable ensures that Railway knows where to look.

TLDR:

Add PORT variable with value 5001.

Change host in your start command to be None.

15 Replies

Railway
BOT

a year ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


a year 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 11 months ago


a year ago

The correct way to use the healthcheck on Railway is specifying the path not the URL. Meaning you'd want /health and not health or https://shopify-data-pipeline-production.up.railway.app/health

What host is your app listening on?


a year ago

/health is what you should be using.

Can you share the entire deployment logs with it set to this?


Anonymous
PRO

a year ago

This typically happens when your application is binding to localhost or 127.0.0.1 instead of 0.0.0.0

Check your application's host binding. Your app needs to listen on 0.0.0.0 (all interfaces) rather than localhost or 127.0.0.1

Verify your PORT environment variable. Railway provides a PORT environment variable

Check your deployment logs for any startup errors or binding messages that might indicate the actual issue.


a year ago

If their application were bound to localhost or 127.0.0.1 we would not be able to access it on the web. That is not the issue.


a year ago

Hey Kafkasl,

Did what Dev and Loudbook suggested solve this issue?


kafkasl
PROOP

a year ago

It seems my app is already listening on 0.0.0.0 and the correct port, but still the healt check fails.


a year ago

Hmmm… Locally if you make a request to the health endpoint does it go through and work?


kafkasl
PROOP

a year ago

Yes it does!

Attachments


kafkasl

Yes it does! ![](https://station-server.railway.com/attachments/att_01k6d7ece9encbpfyb51p6qbm0)

a year ago

And just to repeat myself one more time... do you have a variable named PORT set to be 5001?


kafkasl
PROOP

a year ago

I am unsure where this variable should be because it's already set in the networking and the dockerfile (see images below). Not sure where do I actually need the variable. Afaict railway itself is setting that to 5001.


kafkasl

I am unsure where this variable should be because it's already set in the networking and the dockerfile (see images below). Not sure where do I actually need the variable. Afaict railway itself is setting that to 5001. ![](https://station-server.railway.com/attachments/att_01k6d825t5esk9f5g3ev6vf2va)![](https://station-server.railway.com/attachments/att_01k6d82pzqfqfr36mmsf3f6ej3)

a year ago

(When I say None in this response I mean null, however that applies in Dockerfile or Python.)

Railway's healthcheck uses the PORT variable. It doesn't look at anything else, and it uses the internal IP. Try making a variable named PORT and setting it to 5001, as well as changing your host in that Dockerfile to be None. Changing your host to that ensures that Railway can access it over IPv6, and adding the port variable ensures that Railway knows where to look.

TLDR:

Add PORT variable with value 5001.

Change host in your start command to be None.


a year ago

Recently fixed this same issue here: https://station.railway.com/questions/unable-resolve-health-check-b9f3ba3d#x0kj

Please let me know if this fixes yours as well.


kafkasl
PROOP

a year ago

I managed to fix it, there's more than one combination that works so here's the list:

  1. Add manually PORT variable with 5001 . I thought that railway picked that up already from the networking, where they already ask you which port the app is in, but it seems you need to manually add it anyway. Creating the var inside the Dockefile won't work either.

Depending on whether you want to run uvicorn or python as start command you do:

2a) Python

CMD ["python", "main.py"]  

and in main.py

if name == 'main':

import uvicorn

port = int(os.getenv('PORT', 5001))

uvicorn.run("main:app", host=None, port=port)


**2b) Uvicorn**

```dockerfile
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5001"] 

inside main.py you don't need to do anything.

What did NOT work for me:

CMD ["uvicorn", "main:app", "--host", "::", "--port", "5001"] 
CMD ["uvicorn", "main:app", "--host", "", "--port", "5001"] 
CMD ["uvicorn", "main:app", "--host", "''", "--port", "5001"] 
uvicorn.run("main:app", port=port)
uvicorn.run("main:app", host='', port=port)

samgordon

(When I say `None` in this response I mean null, however that applies in Dockerfile or Python.) Railway's healthcheck uses the PORT variable. It doesn't look at anything else, and it uses the internal IP. Try making a variable named `PORT` and setting it to `5001`, as well as changing your host in that Dockerfile to be `None`. Changing your host to that ensures that Railway can access it over IPv6, and adding the port variable ensures that Railway knows where to look. ⠀ # **TLDR:** Add `PORT` variable with value `5001`. Change host in your start command to be `None`.

kafkasl
PROOP

a year ago

None needs to be 0.0.0.0 when running uvicorn as a command, and None when doing it from python.


Status changed to Solved ray-chen 11 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...