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

CLI hangs forever with some modules #1042

Closed
3 of 7 tasks
simplenotezy opened this issue Aug 9, 2023 · 7 comments
Closed
3 of 7 tasks

CLI hangs forever with some modules #1042

simplenotezy opened this issue Aug 9, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@simplenotezy
Copy link

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

@simplenotezy simplenotezy added the bug Something isn't working label Aug 9, 2023
@jmcdo29
Copy link
Owner

jmcdo29 commented Aug 9, 2023

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?

@simplenotezy
Copy link
Author

@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?

@simplenotezy
Copy link
Author

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

@jmcdo29
Copy link
Owner

jmcdo29 commented Aug 10, 2023

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

@wodCZ
Copy link

wodCZ commented Sep 26, 2023

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?

@micalevisk
Copy link
Contributor

micalevisk commented Oct 4, 2023

@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

@jmcdo29
Copy link
Owner

jmcdo29 commented Oct 23, 2023

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

@jmcdo29 jmcdo29 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants