Backend container exits after a few seconds even though Uvicorn starts correctly

phamphamh
HOBBY

5 months ago

Hi,

I'm experiencing an issue where my backend container shuts down just a few seconds after deployment, even though the logs show that the Uvicorn server starts properly. Here’s what I observe:

  • The deployment logs show:

    INFO:     Uvicorn running on http://0.0.0.0:<port>
    INFO:     Shutting down
    INFO:     Application shutdown complete.
    INFO:     Finished server process [1]
    
  • Then the container stops and the service is marked as failed.

  • I have removed --reload from my startCommand, and I’m correctly using the $PORT variable injected by Railway.

  • My healthcheck path is set to /healthz, and I have verified that this endpoint returns a 200 OK when tested locally.

  • The same command works perfectly on my local machine.

Here is my startCommand:

uvicorn backend.main:app --host 0.0.0.0 --port $PORT --log-level info

I’ve also tried wrapping it via start_backend.py with:

port = int(os.getenv("PORT", 8000))
uvicorn.run(app, host="0.0.0.0", port=port, log_level="info")

But the result is the same — the process starts, then exits within a few seconds.

Is there anything that could be triggering an early shutdown from Railway’s side? Or is there a recent runtime behavior that would cause the container to stop even if Uvicorn is active?

Thanks in advance — I’d really appreciate help figuring this out.

Best,

Solved$10 Bounty

3 Replies

sendcon
FREE

5 months ago

Hello,

Could you increase the log level so we can try to identify any potential issues?
Set log_level to debug: --log-level debug.


sendcon

Hello,Could you increase the log level so we can try to identify any potential issues?Set log_level to debug: --log-level debug.

phamphamh
HOBBY

5 months ago

I put debug, but theres nothing in the debug log


lofimit
HOBBY

5 months ago

I think it's likely because your process exits too fast, maybe you're running a python script that calls uvicorn.run(...) but the script ends right after, so the container just stops.

It could also be the fact uvicorn cannot import your app correctly.


Status changed to Solved chandrika 3 months ago


Backend container exits after a few seconds even though Uvicorn starts correctly - Railway Help Station