Deployment getting crashed
shaktisinghsanwgan
HOBBYOP

18 days ago

I have backend in FastAPI python and database is postgreSQL.

My backend URL env variable : DATABASE_URL="postgresql+asyncpg://${PGUSER}:${PGPASSWORD}@${RAILWAY_PRIVATE_DOMAIN}:5432/${PGDATABASE}"

deployed DB details: DATABASE_URL="postgresql://${{PGUSER}}:${{POSTGRES_PASSWORD}}@${{RAILWAY_PRIVATE_DOMAIN}}:5432/${{PGDATABASE}}"

Now, help me why this error is coming again and again.

Error logs:

Starting Container

INFO: Started server process [1]

INFO: Waiting for application startup.

2026-05-26 17:43:53 | INFO | main | Application starting up

ERROR: Traceback (most recent call last):

File "/app/.venv/lib/python3.11/site-packages/starlette/routing.py", line 693, in lifespan

async with self.lifespan_context(app) as maybe_state:

File "/mise/installs/python/3.11.15/lib/python3.11/contextlib.py", line 210, in aenter

return await anext(self.gen)

       ^^^^^^^^^^^^^^^^^^^^^

File "/app/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 133, in merged_lifespan

async with original_context(app) as maybe_original_state:

File "/mise/installs/python/3.11.15/lib/python3.11/contextlib.py", line 210, in aenter

return await anext(self.gen)

       ^^^^^^^^^^^^^^^^^^^^^

File "/app/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 133, in merged_lifespan

async with original_context(app) as maybe_original_state:

File "/mise/installs/python/3.11.15/lib/python3.11/contextlib.py", line 210, in aenter

return await anext(self.gen)

       ^^^^^^^^^^^^^^^^^^^^^

File "/app/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 133, in merged_lifespan

async with original_context(app) as maybe_original_state:

File "/app/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 133, in merged_lifespan

File "/mise/installs/python/3.11.15/lib/python3.11/contextlib.py", line 210, in aenter

File "/app/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 133, in merged_lifespan

return await anext(self.gen)

File "/mise/installs/python/3.11.15/lib/python3.11/contextlib.py", line 210, in aenter

async with original_context(app) as maybe_original_state:

async with original_context(app) as maybe_original_state:

       ^^^^^^^^^^^^^^^^^^^^^

       ^^^^^^^^^^^^^^^^^^^^^

File "/app/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 133, in merged_lifespan

return await anext(self.gen)

File "/mise/installs/python/3.11.15/lib/python3.11/contextlib.py", line 210, in aenter

return await anext(self.gen)
$10 Bounty

2 Replies

Status changed to Open Railway 18 days ago


abhishekmitra-ait
FREE

18 days ago

Hi @shaktisinghsanwgan, can you grant me access to your project?


17 days ago

The first thing I’d fix is the DATABASE_URL itself. Right now it looks like you’re mixing normal shell-style env vars (${PGUSER}) with Railway reference vars (${{ ... }}). Railway won’t expand ${PGUSER} inside another variable unless your app/shell is doing that later.

On the FastAPI service, I’d set the DB URL using Railway references to the actual Postgres service, something like:

DATABASE_URL=postgresql+asyncpg://${{Postgres.PGUSER}}:${{Postgres.POSTGRES_PASSWORD}}@${{Postgres.RAILWAY_PRIVATE_DOMAIN}}:5432/${{Postgres.PGDATABASE}}

Replace Postgres with the exact database service name. Also check whether your DB service exposes POSTGRES_PASSWORD or PGPASSWORD and don’t mix them. One missing value here is enough for FastAPI to crash during startup before it ever serves a request.

Also don’t wrap the value in quotes in Railway Variables. Put the raw URL only, otherwise some apps read the quotes as part of the URL.

If it still crashes after that, paste the last 10-20 lines after return await anext(self.gen). The useful error is probably just below the truncated part, usually auth failed / could not resolve host / connection refused.


Welcome!

Sign in to your Railway account to join the conversation.

Loading...