Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoiding EADDRINUSE with HMR #2627

Open
2 of 4 tasks
laino opened this issue Feb 14, 2023 · 2 comments
Open
2 of 4 tasks

Avoiding EADDRINUSE with HMR #2627

laino opened this issue Feb 14, 2023 · 2 comments

Comments

@laino
Copy link

laino commented Feb 14, 2023

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
@micalevisk
Copy link
Member

would you like to open a PR at https://github.com/nestjs/docs.nestjs.com

image

@laino
Copy link
Author

laino commented Feb 14, 2023

Thanks for the pointer. I'll do so once I'm reasonably sure that this fixed the sporadic EADDRINUSE I've been getting.

@kamilmysliwiec kamilmysliwiec transferred this issue from nestjs/nest Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants