Scheduled tasks keep Bun process alive after graceful shutdown
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
Environment
- Nitro: current
main(eee0abd9fc4f729445f5b1a4da06fa78daf7a3da) and3.0.260610-beta - Preset:
bun - Bun:
1.3.14 - OS: macOS arm64
Reproduction
Configure one scheduled task:
export default defineNitroConfig({
preset: "bun",
experimental: {
tasks: true,
},
scheduledTasks: {
"*/5 * * * *": ["test"],
},
});
Build and start the server, then send SIGTERM:
pnpm nitro build
bun .output/server/index.mjs &
pid=$!
sleep 1
kill -TERM "$pid"
sleep 10
kill -0 "$pid"
The HTTP server logs Server closed successfully., but the process remains alive and kill -0 succeeds. The behavior reproduces without Redis or other external connections.
Description
startScheduleRunner() creates a Croner instance with the default unref: false option and discards the instance:
new Cron(schedule.cron, callback);
After the HTTP listener closes, the referenced Croner timeout keeps the Bun event loop alive. Containers therefore require a forced kill during shutdown.
Passing { unref: true } to Croner allows the process to exit after the server closes without changing task scheduling while the server is running.
I will submit a focused PR with a regression test.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at startScheduleRunner() and inspect the Croner construction described in the issue. Verify the shutdown behavior with the provided Bun reproduction, then add the requested regression test and confirm that the process exits after the HTTP server closes while scheduled tasks still run normally.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bun, typescript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100