Auto-restart (on normal exit, not crash) is failing sometimes
pauldps
HOBBYOP

5 hours ago

I have a service that automatically shuts down (gracefully, with an exit code 0) when memory usage reaches a certain threshold. I have Railway set to always restart. It works most of the time, but sometimes Railway will not pick it up and the service will go down silently. It has happened twice now, in different weeks. I have to manually restart the service to bring it back up.

When the issue happens,the last line in the logs is always: "Mounting volume on: ..." then it just sits there.

I cannot use Serverless because my server runs background jobs. Serverless is also not working correctly with the constant 502s, but as that's expected from the feature it's just not suitable for my case.

Any suggestions on how to fix this? Is the number of restarts (limited to 10 when restarting on crashes) also applying to normal restarts? My app is not crashing at all so I'd think that limit would not apply.

$10 Bounty

3 Replies

Railway
BOT

5 hours ago

Your service's restart policy is currently set to "On Failure" (not "Always"), which only restarts on non-zero exit codes. A graceful exit with code 0 will not trigger a restart under that policy, which explains why the service stays down after your memory-threshold shutdown. Change the restart policy to "Always" in Service Settings > Deploy, and note that your config-as-code file at /api/config/railway.toml can override dashboard settings, so check there as well. The 10-retry limit applies only to "On Failure" restarts and does not cap "Always" restarts on paid plans.


Status changed to Awaiting User Response Railway about 5 hours ago


Railway

Your service's restart policy is currently set to "On Failure" (not "Always"), which only restarts on non-zero exit codes. A graceful exit with code 0 will not trigger a restart under that policy, which explains why the service stays down after your memory-threshold shutdown. Change the restart policy to "Always" in Service Settings > Deploy, and note that your config-as-code file at `/api/config/railway.toml` can override dashboard settings, so check there as well. The 10-retry limit applies only to "On Failure" restarts and does not cap "Always" restarts on paid plans.

pauldps
HOBBYOP

5 hours ago

My confilg file has this line:

restartPolicyType = "ALWAYS"

Isn't that the correct syntax?


Status changed to Awaiting Railway Response Railway about 5 hours ago


Railway
BOT

5 hours ago

This thread has been opened as a bounty so the community can help solve it.

Status changed to Open Railway about 5 hours ago


pauldps

My confilg file has this line: restartPolicyType = "ALWAYS" Isn't that the correct syntax?

pm6guy10
FREE

41 minutes ago

restartPolicyType = "ALWAYS" is right.

The Mounting volume on: line means Railway did attempt the restart. It looks like the new container is occasionally getting stuck during volume/startup, not failing to restart.

Since you’re intentionally recycling for memory, I’d restart the worker process inside the container instead of exiting the whole container each time.

That avoids remounting the volume on every recycle.


Welcome!

Sign in to your Railway account to join the conversation.

Loading...