jmcdo29/nest-commander

CLI hangs forever with some modules

Closed this issue · 7 comments

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

If I add:

BullModule.forRootAsync({
  useFactory: ConfigFactory.bullConfig,
  inject: [ConfigService],
}),

To my CliModule it will always run, so if we have cron jobs that uses a cli command it will keep reporting as 'Running'.

If I remove the BullModule the command will exit as usual.

Minimum reproduction code

https://github.com/simplenotezy/bullmq-and-commander

Run docker-compose up to get a redis instance spinning and then you can run node dist/cli basic and you'll notice it hangs.

Note: it only happens when after adding the TestProcessor to AppModule. If you remove the processor, it will work fine.

Expected behavior

Should not hang

Package

  • nest-commander
  • nest-commander-schematics
  • nest-commander-testing

Package version

N/A

Node.js version

No response

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

Related to: #945

As mentioned in the discussion, it looks like things do end up closing and exiting, it just takes time, for whatever reason. Are you seeing that it is truly hanging indefinitely now?

@jmcdo29 Just clone the reproduction repo but I agree, it seems to end up closing. However, ideally it should exit instantly. Do you have any workaround / solution to have it exit once done?

In our production repo I can confirm it hangs forever, it could be related to other modules, but I assume the underlying issue is the same, and if it could be fixed in the redis example, I think it would fix other similar issues as well

So, I took your example, and modified it a bit to see if this is directly related to nest-commander, or something else. Changing the main.ts to this:

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

async function bootstrap() {
  // const app = await NestFactory.create(AppModule);
  // await app.listen(3000);
  const app = await NestFactory.createApplicationContext(AppModule);
  console.log(app.get(AppService, { strict: false }).getHello());
  await app.close();
}
bootstrap();

And running it twice results in the same behavior. It would seem like a queue is being created and not closed immediately. I haven't found the why of that, but I don't believe this is related to nest-commander

Hi, I'll join this discussion with similar findings to Jay's.

In my case, a regular NestFactory.create(AppModule) exits properly, but the following hangs indefinitely when attempting any kind of exit:

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

async function bootstrap() {
  const replServer = await repl(AppModule);
  replServer.setupHistory('.nestjs_repl_history', (err) => {
    if (err) {
      console.error(err);
    }
  });
}

bootstrap().catch(console.error);

I've traced it down to bull/redis - the repl stops correctly when I comment out all registerQueue calls.

But maybe it's a different issue, on repl from @nestjs/core?

@wodCZ maybe? probably due to the app bellow. Not sure why either. There's no 'close' step from ReplContext side

image
https://github.com/nestjs/nest/blob/49cf54e10aed6d30c47bad5975e5141ceeae1b1f/packages/core/repl/repl.ts#L15

I'm going to close this as it doesn't seem to be directly related to nest-commander