Worker / Discord bot container keeps receiving SIGTERM even though process is healthy
rezaza1234
HOBBYOP

2 months ago

Hello, I am running a Discord bot (Node.js, discord.js) on Railway and I’m having an issue where the container is being force-stopped with SIGTERM even though the process is healthy and logged in successfully.

What happens:

The container starts normally.

The bot logs in to Discord successfully.

After ~10–30 seconds, Railway sends SIGTERM and stops the container.

There is no crash in the application — the shutdown always comes from Railway.

Example logs:

Starting Container
GUILD MEMBER ADD FILE LOADED
✅ Logged in as Steward#4758
[BumpReminder] Initialized.
🟡 Vote webhook disabled (worker mode, no HTTP server).
[BumpReminder] Loaded last bump from history: …
Stopping Container
npm error signal SIGTERM

What I have already checked / changed:

This is intended to be a background worker (Discord bot), not a web service.

No HTTP server is running anymore (webhook disabled).

Serverless is OFF.

Healthcheck path is EMPTY.

No cron schedules configured.

No public domains / public networking.

Custom start command set to:
node dist/index.js

Environment variables (including DISCORD_TOKEN) are correctly set and verified in the UI.

The bot runs fine locally and logs in before Railway stops it.

Symptoms across multiple attempts:

Even after disabling webhook + removing HTTP listeners, Railway still terminates the container with SIGTERM.

Same behavior happened with both an old service and a newly created service.

My suspicion:
Railway may still be treating this service as a web service instead of a worker, or there is an internal idle / lifecycle rule causing background processes to be terminated.

Could you please:

Confirm whether this service is being treated as a web service or worker internally?

Check why SIGTERM is being sent to a healthy running process?

Advise the correct way to run a persistent Discord bot / worker on Railway?

Thank you very much, I am happy to provide project ID or logs if needed.

Best,
Hallvard

Solved$10 Bounty

51 Replies

rezaza1234
HOBBYOP

2 months ago

Project ID:
4ad0daef-0101-4a89-bd13-8e6b477312cd
Service ID:
3c953baa-b27f-4500-8de3-8a231c745a1d


2 months ago

Hey, on Railway there's no such difference between web service and a worker, both of them are treated as a service and will run indefinitely. One thing that I can think off is that your background service is using way too memory and thus OOM acts on it.


rezaza1234
HOBBYOP

2 months ago

Hi again,

That is interesting, the process is very small (Discord.js bot, no web server running, no heavy tasks), and it consistently gets terminated within 20-30 seconds even though it logs in successfully.

A few questions that I have;

Is the container actually being killed by OOM (out-of-memory), or is it receiving a normal SIGTERM from the platform?
Is there a way to see the memory usage graph or the exact reason for the SIGTERM for this service?
What memory limit is currently applied to this service/environment?

In the logs I only see:
Stopping Container npm error signal SIGTERM

No stack trace or crash from Node itself.

If this is OOM-related, I’d like to confirm whether:
The service is hitting a memory limit, or if there is some automatic idle / lifecycle rule still stopping it


2 months ago

On your service metrics, there's a memory chart, however, if your service experiences a rapid spike in memory usage, the chart often fails to register it. I can assure you that Railway has no idle / lifecycle rule


2 months ago

The memory limits depends on your plan, if you're on a Hobby plan, the limits are 8gb and 8vCPU per service.


rezaza1234
HOBBYOP

2 months ago

Thanks, that rules out OOM then I guess…

Since the service has 8GB RAM and still receives SIGTERM shortly after startup, could you please check from the platform side:

  • What component is sending the SIGTERM (supervisor / deploy system / lifecycle manager)?

  • Whether the process is being considered “completed” or “exited” by Railway?

Right now the service is started with:
node dist/index.js

The bot logs in successfully and stays running (event loop active), but Railway still stops it.

Is there any requirement for background services to keep STDOUT active or to prevent the supervisor from treating the process as finished?


2 months ago

I'm not part of the Railway team, just a community member, unfortunately can't do that for you.


rezaza1234
HOBBYOP

2 months ago

ah okay that makes sense, do you have a suggestion for what I can do to try and fix this? im kind of lost haha 😅 maybe I can force the process to never look idle or something?


rezaza1234
HOBBYOP

2 months ago

imma try and apply

setInterval(() => {}, 1 << 30);

to the bottom of my index.ts, hopefully it will keep the event loop permanently alive and preventing it from thinking it finished?


2 months ago

Again, there's no system for killing your application if it's on idle (well, only if you're on Serverless, but you said that it's disabled). Railway does not detect any sort of event loop idle.


rezaza1234
HOBBYOP

2 months ago

okay gotcha, well then I am out of ideas on how to fix this lol, I feel like I tried everything


2 months ago

I'm doing some tests now to check if Railway emits alerts for OOM, give me a minute.


rezaza1234
HOBBYOP

2 months ago

hm, then it sounds like the node process itself may be exiting on its own and Railway is only sending SIGTERM after the process ends.

In that case I suspect something in my code (or one of the background systems like BumpReminder / DB init / startup flow) is calling process.exit() or throwing an unhandled error after initialization, but I am not sure what does this…

Do you by chance know if Railway logs anywhere whether the process exits normally vs being force-killed? Or if there is a way to see the real exit code before SIGTERM?

From my perspective, the bot logs in successfully and then the container stops with no visible stack trace :/


2 months ago

Do you maybe see this error on our service?

1464781659227291600


rezaza1234
HOBBYOP

2 months ago

nope, never seen that yet.

1464781940996444400


rezaza1234
HOBBYOP

2 months ago

the one to the left is a new one i just made an hour ago or so to see if the issue was related to something else but it didnt work out lol


2 months ago

and regarding your question, no I don't think Railway logs that. Then yeah, I think your service is crashing somewhere else.
Maybe you can add those lines to check?

    process.on('unhandledRejection', (error) => { 
      console.log(`Unhandled Rejection: ${error}`); 
    });

    process.on('uncaughtException', (error) => { 
      console.log(`Uncaught Exception: ${error}`); 
    });

rezaza1234
HOBBYOP

2 months ago

gotcha, well I already have this implemented into my index file from earlier, had the same idea


2 months ago

uhmm no logs then? yeah definitely weird.


rezaza1234
HOBBYOP

2 months ago

Yeah very weird, it should have been working by now I imagined :/ It doesn’t look like an exception or rejection.

And the shutdown always happens right after this log line:
[BumpReminder] Loaded last bump from history: ...


2 months ago

instead of using npm, try using the node command directly, might help a little bit more


2 months ago

I've heard some weird issues with package mangers running commands on Railway due to how they handle signals but just shot in the dark


rezaza1234
HOBBYOP

2 months ago

oh yeah and I also have npm start


rezaza1234
HOBBYOP

2 months ago

ill try something rq, ill have a look at one of my other files that prints
[BumpReminder] Loaded last bump from history
and see if there is something I oversee


2 months ago

Try adding try catch everywhere 🥲


2 months ago

Also Railway offers SSH, might help the debug part a little bit more tolerable. And try to replicate your Railway environment as close as possible (same env variables and all), if it crashes then a debugger would be the option.


2 months ago

If your code is public, I wouldn't mind taking a look too <:salute:1137099685417451530> really intrigued by this.


rezaza1234
HOBBYOP

2 months ago

Okay, I have now added extensive logging in index.ts (exit / beforeExit / startup try-catch) to catch any silent exits, and I’m redeploying to see if I can capture where the process ends. I’ll also try reproducing it locally with the same env variables. The code is currently private, but if this continues I can make a minimal public reproduction or share the relevant files with you! I’m very curious about what is causing this issue myself lol.

I really appreciate you out here trying to help me out bro! This has been bugging me for 2 days now haha and I am getting really tired of it. xD


2 months ago

Let me know how it goes! and I understand your pain, had the same issue of silently crashing, replicating the environment did the trick for me


rezaza1234
HOBBYOP

2 months ago

okay I have ran some testing but it seems with no good results. If this build I am deploying right now doesnt work I'll let you have a look if you are still interested!


2 months ago

Yep, totally just let me know. If you prefer to give me private access, just send me an invite to my github at


rezaza1234
HOBBYOP

2 months ago

okay just invited you!


2 months ago

Can you change your railway.json code to use Railpack instead? we're deprecating Nixpacks.


rezaza1234
HOBBYOP

2 months ago

alright, did so and also start command runs through railway.json now. Redeploying now, will update you with logs

1464801661577986300


rezaza1234
HOBBYOP

2 months ago

The bot now boots successfully, logs in to Discord, finishes startup, and prints:
🟢 STARTUP SEQUENCE COMPLETE — BOT SHOULD STAY ONLINE

But a few seconds later Railway still sends SIGTERM and stops the container with no crash, no exception, no OOM, no unhandledRejection, or uncaughtException logs.

FYI:
Serverless is OFF
No healthcheck
No cron
No public domain
No HTTP server running


rezaza1234
HOBBYOP

2 months ago

this is with the most recent deployment^


rezaza1234
HOBBYOP

2 months ago

I'm off to bed soon, and again, I really appreciate you being interested in helping! Please just reach out and tell me if you got something, and I will respond again once I am up tomorrow!


2 months ago

Mine seems to be staying online, will try with more real env variables to confirm

1464803110194254000


rezaza1234
HOBBYOP

2 months ago

ooo okay that is very strange…


rezaza1234
HOBBYOP

2 months ago

could my variables be at fault maybe?


2 months ago

maybe the env variables are not triggering the exact state you're in so let me confirm mine first


rezaza1234
HOBBYOP

2 months ago

I think it makes sense in a way then. The crashing started happening once all my real env vars are loaded and startup finishes, before that it seemed stable and good. Let me know what variables or config you want me to share so you can match the environment as closely as possible! Thanks again my friend!


2 months ago

mine still seems to not crash with real env variables

1464805586330718500


2 months ago

really do not know what I could do to replicate it even more


rezaza1234
HOBBYOP

2 months ago

Okay that’s really nice to see but still very strange to me. I’ll have a look at the variables again tomorrow and perhaps you can help me out and we can see if there is something very wrong. Does that sound okay to you?


2 months ago

Yep, no problem, see you tomorrow!


rezaza1234
HOBBYOP

2 months ago

Alright, since the same code + env vars don’t crash on your side, it must be something specific to my Railway deployment/runtime…

What seems different on my side:

  • Hobby plan

  • Using tsx (not prebuilt dist)

  • Start command: tsx src/index.ts

  • Builder was Nixpacks originally, now trying Railpack

Let me know what you want me to change next (builder, Node version, start command, etc). I can also give you temporary Railway access if needed! :D


rezaza1234
HOBBYOP

2 months ago

This is my most recent log output

1464961354107457617


rezaza1234
HOBBYOP

2 months ago

I see that the logs updated after supposedly Stopping, and features like Bump reminder still works. Is this perhaps just Railway being dumb and false claiming the process is stopped?
Stopping Container npm error path /app npm error command failed npm error signal SIGTERM npm error command sh -c tsx src/index.ts npm error A complete log of this run can be found in: /root/.npm/_logs/2026-01-25T01_58_09_591Z-debug-0.log [BumpReminder] Reminder sent. [BumpReminder] Reminder sent. [BumpReminder] New DISBOARD message detected. lastBumpAt=2026-01-25T12:33:43.648Z [BumpReminder] New DISBOARD message detected. lastBumpAt=2026-01-25T12:33:43.648Z


franzi-4
PRO

2 months ago

So turns out the SIGTERM logs are kinda misleading, the bot is probably still running fine since BumpReminder keeps working after the "stop" lol. Try running Node directly with node dist/index.js instead of npm/tsx, and switch to Railpack in your railway.json. If your bot responds in Discord and stays connected, you should be good, worked for me at least


2 months ago

That's good to know, and yeah no idea what's happening but if it's working then I'm closing this thread.


Status changed to Solved passos about 2 months ago


Loading...