Skip to content

Avoiding EADDRINUSE with HMR #2627

Open
@laino

Description

@laino

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When using the default HMR example EADDRINUSE errors can occur, likely because close() is not awaited.

Maybe the example should look something like this instead:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
    if (module.hot?.data?.closePromise) {
        await module.hot.data.closePromise;
        module.hot.data.closePromise = null;
    }

    const app = await NestFactory.create(AppModule, {
        forceCloseConnections: !!module.hot,
    });

    if (module.hot) {
        module.hot.accept();
        module.hot.dispose((data) => data.closePromise = app.close());
    }

    await app.listen(3000);
}

bootstrap();

Minimum reproduction code

https://docs.nestjs.com/recipes/hot-reload

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions