Backend 502 at edge after every deploy — only manual redeploy fixes it
tlaneur9
HOBBYOP

9 days ago

Hey — running into a weird recurring issue and wondering if anyone's seen this.

My backend service is a FastAPI + uvicorn app on Hobby tier (us-east4-eqdc4a). Yesterday I migrated from Nixpacks to a Dockerfile-based build (Playwright base image: mcr.microsoft.com/playwright/python:v1.59.0-jammy).

Since then, every git push has the same pattern:

  1. Build phase succeeds
  2. Container starts, alembic migrations run, uvicorn binds to 0.0.0.0:$PORT
  3. Deploy logs show internal /health returning 200
  4. But Railway's edge returns {"status":"error","code":502,"message":"Application failed to respond"} until I click ⋮ → Redeploy from the dashboard
  5. After the manual redeploy, the edge starts routing correctly and the app works for hours

It's happened on 3 separate pushes now (Step 1 Dockerfile switch, Step 2 endpoint addition, and a revert). Each time, manual redeploy fixes it.

Has anyone seen this where the edge router doesn't pick up a freshly-deployed container until a manual redeploy? Is there something in my Dockerfile or railway.toml that could be causing it?

Dockerfile is minimal — just FROM ..., WORKDIR /app, COPY requirements.txt + pip install, COPY . ., and CMD ["sh", "-c", "alembic ... && uvicorn main:app --host 0.0.0.0 --port $PORT"]. railway.toml has builder = "DOCKERFILE", dockerfilePath = "backend/Dockerfile", healthcheckPath = "/health".

Any pointers appreciated.

Solved$10 Bounty

Pinned Solution

Try to decouple your database migrations from your web server startup. I suggest you move your alembic command from CMD in your Dockerfile and make it a pre-deploy command. It could be the reason for delaying your web server from binding to a port and causing the 502 error.

2 Replies

Status changed to Open Railway 9 days ago


Try to decouple your database migrations from your web server startup. I suggest you move your alembic command from CMD in your Dockerfile and make it a pre-deploy command. It could be the reason for delaying your web server from binding to a port and causing the 502 error.


darseen

Try to decouple your database migrations from your web server startup. I suggest you move your alembic command from `CMD` in your Dockerfile and make it a pre-deploy command. It could be the reason for delaying your web server from binding to a port and causing the 502 error.

tlaneur9
HOBBYOP

2 days ago

Solved. Thank you!


Status changed to Solved brody 2 days ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...