Skip to content

Nuxt does not await for Nitro to close properly before reloading server #32928

@Gwynerva

Description

@Gwynerva

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.

Image

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions