-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
Description
Environment
Windows 11
Nuxt 4.0.3
Bun
Reproduction
https://github.com/Gwynerva/nuxt-nitro-close-bug
Describe the bug
Nitro close
hook can accept async functions.
export default defineNitroPlugin((nitro) => {
console.log('\n\n\n=====');
console.log('My Nitro Plugin INIT!');
nitro.hooks.hook('close', async () => {
console.log('My Nitro Plugin Close START!');
await new Promise((resolve) => setTimeout(resolve, 3000));
console.log('My Nitro Plugin Close END!');
});
});
When the change is made to any Nuxt server files (including plugin file), Nuxt will rebuild and restart the server.
The problem is that Nuxt is not waiting for Nitro to close properly and just immediately restarts it causing really bad "boot"/"close" overlapping.

For example, there is no way to properly close database connection or clear files.
This leads to immediate crashes when rebooted server tries to establish DB connection to a file that it the same time gets deleted by previously closing Nitro.