nestjs / mongoose

Mongoose module for Nest framework (node.js) 🍸
https://nestjs.com
MIT License
520 stars 116 forks source link

Unhandled promise rejections during MongooseModule initialization #1057

Open ukito-pl opened 2 years ago

ukito-pl commented 2 years ago

Did you read the migration guide?

Is there an existing issue that is already proposing this?

Potential Commit/PR that introduced the regression

No response

Versions

8.0.1 -> 9.0.0

Describe the regression

Hi, I recently upgraded @nestjs/mongoose to 9.0.0 and mongoose to 6.0.9.

Since then mongoose errors are not being caught. If there is any exception being thrown during establishing connection it results in unhandled promise rejection. In the snippet below I set retryAttempts to 10, but there is unhandled promise rejection after 1st failed connection attempt and there are no further attempts.

Minimum reproduction code

@Module({
  imports: [
    MongooseModule.forRoot(
      'mongodb://user:pass@localhost:27020/main?authSource=admin',
      { retryAttempts: 10 },
    ),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Here is full reproduction repository: https://github.com/ukito-pl/nest-mongoose-bug

Expected behavior

I expect that in case of connection error Mongoose will retry connection according to 'retryAttempts' option and will not cause unhandled promise rejections.

Other

No response

kamilmysliwiec commented 2 years ago

Please provide a minimum reproduction repository as a Github repository.

ukito-pl commented 2 years ago

Here is github repo: https://github.com/ukito-pl/nest-mongoose-bug

gsaint commented 2 years ago

Having the same issue here!

jordanberry commented 2 years ago

Experiencing the same, happy to help triage - appreciate the great framework 👍