$ node .output/server/index.mjs
Listening on http://[::]:3000
Press Ctrl + C to send SIGINT to the process and observe the expected output:
^CDisconnecting database...
Database is disconnected!
Run the Nitro server with bun:
bun .output/server/index.mjs
Listening on http://[::]:3000
Press Ctrl + C to send SIGINT to the process and observe the expected output:
^CDisconnecting database...
Database is disconnected!
The close hook runs whether the runtime is node or bun given that the build used the node-server preset.
Reproduce that the close hook fails to run when built with the bun preset.
Remove the .nitro and .output directories:
rm -rf ./nitro ./output
Build using the bun preset:
pnpm exec nitro build --preset bun
Run the Nitro server:
$ bun .output/server/index.mjs
Listening on http://localhost:3000...
Press Ctrl + C to send SIGINT to the process and observe the output:
^C
The code specified in the close hook never runs.
Describe the bug
When using the Nitro web server built with the bun preset, the close hook fails to run upon receiving a SIGINT signal (Ctrl + C). This behavior contrasts with the expected functionality observed when using the node-server preset, where the close hook executes properly under both Node.js and Bun runtimes.
Specifically, when built with the node-server preset, pressing Ctrl + C results in the expected output:
Disconnecting database...
Database is disconnected!
However, when built with the bun preset and run using Bun, pressing Ctrl + C simply terminates the process without executing the close hook, resulting in no output.
This issue prevents proper graceful shutdown procedures from being executed when using the bun preset, which could lead to resource leaks or incomplete cleanup operations in production environments.
Note: The root cause of this issue has not been isolated, and therefore, I am unable to submit a pull request with a fix at this time.
Environment
Reproduction
Validate that, when built with the
node-server
preset, theclose
hook runs as expected under both Node.js and Bun runtimes:Install and build using the default
node-server
preset:Run the Nitro server with
node
:Press Ctrl + C to send
SIGINT
to the process and observe the expected output:Run the Nitro server with
bun
:Press Ctrl + C to send
SIGINT
to the process and observe the expected output:The
close
hook runs whether the runtime isnode
orbun
given that the build used thenode-server
preset.Reproduce that the
close
hook fails to run when built with thebun
preset.Remove the
.nitro
and.output
directories:Build using the
bun
preset:Run the Nitro server:
SIGINT
to the process and observe the output:The code specified in the
close
hook never runs.Describe the bug
When using the Nitro web server built with the
bun
preset, theclose
hook fails to run upon receiving a SIGINT signal (Ctrl + C). This behavior contrasts with the expected functionality observed when using thenode-server
preset, where theclose
hook executes properly under both Node.js and Bun runtimes.Specifically, when built with the
node-server
preset, pressing Ctrl + C results in the expected output:However, when built with the
bun
preset and run using Bun, pressing Ctrl + C simply terminates the process without executing theclose
hook, resulting in no output.This issue prevents proper graceful shutdown procedures from being executed when using the
bun
preset, which could lead to resource leaks or incomplete cleanup operations in production environments.Note: The root cause of this issue has not been isolated, and therefore, I am unable to submit a pull request with a fix at this time.
Additional context
No response
Logs
No response