R
Railway8mo ago
M.

FastAPI service health-check fails in IPV6

I'm running a fastAPI service in railway. I setup a /healthcheck endpoint. It worked well when I exposed it publicly and bound it to 0.0.0.0:8000 (I've also specified the PORT=8000 env var). However, I want an nginx reverse proxy to be the only publicly exposed service since that backend service will work alongside a separate nextjs frontend service (that won't be publicly exposed either). In trying to communicate the service privately though, I changed the host to :: (same 8000 port) as per the private networking docs: https://docs.railway.app/guides/private-networking#listen-on-ipv6 and railway can't hit the /healthcheck endpoint anymore and so the build logs say the service never came online. Any thoughts?
Railway Docs
Private Networking | Railway Docs
Documentation for Railway
29 Replies
Percy
Percy8mo ago
Project ID: 2cc7bfdb-9bfd-4c76-8d34-28e269d7406f
M.
M.OP8mo ago
Project ID: 2cc7bfdb-9bfd-4c76-8d34-28e269d7406f
Brody
Brody8mo ago
Uvicorn does not support dual stack binding (IPv6 and IPv4) from the CLI, so while that start command will work to enable access from within the private network, this prevents you from accessing the app from the public domain if needed, I recommend using Hypercorn instead
M.
M.OP8mo ago
I don't need to access it from the public domain though
Brody
Brody8mo ago
health checks use ipv4 an example hypercorn start command would be hypercorn main:app --bind [::]:$PORT
M.
M.OP8mo ago
Whoa >health checks use ipv4 Any chance you could mention that in the docs?
Brody
Brody8mo ago
of course you'd want to set a fixed PORT service variable will bring that up to the applicable person
M.
M.OP8mo ago
Thanks! So if I disable the healthchecks all should work well, correct?
Brody
Brody8mo ago
yeah but i wouldnt disable the health check, i would use hypercorn
M.
M.OP8mo ago
Noted! Our production systems are battle tested on uvicorn. I can't justify switching over given that railway only has healthchecks over ipv4 though. It would also be a non trivial change in the codebase
Brody
Brody8mo ago
thats fair, but without a health check railway wont know when your app is able to handle traffic
M.
M.OP8mo ago
Yup, understood. I'm running an MVP to test out the viability of switching our k8s cluster over to railway. If we do decide to pull the trigger on the migration we would consider switching to accomodate for the healthchecks
Brody
Brody8mo ago
sounds good, and with the upcoming runtime im sure adding ipv6 capabilities to the health check would be already done by default or easy enough to implement
M.
M.OP8mo ago
Nice! That's good to hear! Do you have a rough ETA for when those changes would land?
Brody
Brody8mo ago
runtime v2 is pre-alpha right now, so i dont have any real eta to give you, and in fact the v2 runtime doesnt even support any health checks right now
M.
M.OP8mo ago
Coming back to this, my nginx service isn't able to communicate with the fastapi service
Brody
Brody8mo ago
lets see the nginx.conf
M.
M.OP8mo ago
I've disabled the healthcheck and have nginx pointed to http://upcodes-backend.railway.internal:8000
server {
listen 80;

location /v0 {
proxy_pass http://upcodes-backend.railway.internal:8000;
}


location / {
proxy_pass http://upcodes-frontend.railway.internal;
}
}
server {
listen 80;

location /v0 {
proxy_pass http://upcodes-backend.railway.internal:8000;
}


location / {
proxy_pass http://upcodes-frontend.railway.internal;
}
}
Brody
Brody8mo ago
nginx is not ideal for this, but i assume you dont want to switch to caddy?
M.
M.OP8mo ago
Is there are reason why nginx wouldn't work? Happy to switch if that helps/is easier nginx is a typical reverse proxy for these things
Brody
Brody8mo ago
nginx tries to resolve the domains at first start, this is not ideal for two resaons, the private network is not available at first start, the services do not have static ip(v6) addresses of course nginx can be configured to not do these things, but caddy doesnt do them by default
M.
M.OP8mo ago
Interesting. I'll give caddy a shot. Looks like you configured the template!
Brody
Brody8mo ago
yep that template covers your use case, though mine calls the backend endpoint /api but thats a simple change
M.
M.OP8mo ago
Cool! What whould that change look like? I'm not familiar with caddy
Brody
Brody8mo ago
/api/* -> /v0/*
M.
M.OP8mo ago
Right but where? Ah nvm I see the Caddyfile in the repo.
Brody
Brody8mo ago
yeah you would need to deploy the template and then eject from it
M.
M.OP8mo ago
Cool. Yeah, just copy pasted your code into my repo and deployed from there
Brody
Brody8mo ago
sounds good
Want results from more Discord servers?
Add your server