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

NestFactory.createApplicationContext run successfully but never exit. How to shutdown app gracefully? #503

Closed
janckerchen opened this issue Mar 13, 2018 · 7 comments

Comments

@janckerchen
Copy link

commented Mar 13, 2018

I love this idea so much, Thanks to that, you can take advantages of the Nest framework everywhere, including CRON jobs and even build a CLI on top of it., but stuck.

create app context and invoke marketService.test()

import { NestFactory } from "@nestjs/core";
import { ApplicationModule } from "../../src/app.module";
import { TradeModule } from "../../src/trade/trade.module";
import { MarketService } from "../../src/trade/services";

const run = async () => {
    const app = await NestFactory.createApplicationContext(ApplicationModule);
    const marketService: MarketService = app.select(TradeModule).get(MarketService);
    marketService.test();
}

run();

marketService.test() log message successfully, but script never exit. how can I use i in CRON?

4:38 $ ts-node script/app/context.ts
[Nest] 68465   - 2018/3/13 下午2:38:21   [NestFactory] Starting Nest application...
(node:68465) Warning: N-API is an experimental feature and could change at any time.
[Nest] 68465   - 2018/3/13 下午2:38:22   [InstanceLoader] ApplicationModule dependencies initialized +29ms
[Nest] 68465   - 2018/3/13 下午2:38:22   [InstanceLoader] MongooseModule dependencies initialized +1ms
[Nest] 68465   - 2018/3/13 下午2:38:22   [InstanceLoader] MongooseCoreModule dependencies initialized +91ms
[Nest] 68465   - 2018/3/13 下午2:38:22   [InstanceLoader] AppConfigModule dependencies initialized +1ms
[Nest] 68465   - 2018/3/13 下午2:38:22   [InstanceLoader] TradeModule dependencies initialized +23ms
[Nest] 68465   - 2018/3/13 下午2:38:22   [InstanceLoader] MongooseModule dependencies initialized +2ms
MarketService test

<----- !!!stop here, never exit!!!

@janckerchen janckerchen changed the title NestFactory.createApplicationContext run successfully but never stop. NestFactory.createApplicationContext run successfully but never exit. Mar 13, 2018

@janckerchen

This comment has been minimized.

Copy link
Author

commented Mar 13, 2018

maybe mongoose open database connection and not closed properly.
mongoose.connection.close() don't do the trick. how to shutdown app gracefully?

@janckerchen janckerchen changed the title NestFactory.createApplicationContext run successfully but never exit. NestFactory.createApplicationContext run successfully but never exit. How to shutdown app gracefully? Mar 14, 2018

@kamilmysliwiec

This comment has been minimized.

Copy link
Member

commented Mar 28, 2018

Looking into this now. Thanks for reporting!

@kamilmysliwiec

This comment has been minimized.

Copy link
Member

commented Apr 20, 2018

Fixed in the incoming v5.0.0 release.

@kamilmysliwiec kamilmysliwiec self-assigned this Apr 20, 2018

@kamilmysliwiec kamilmysliwiec added this to the 5.0.0 milestone Apr 20, 2018

@v-dyatlov

This comment has been minimized.

Copy link

commented Jul 19, 2018

I have the same problem with cron job.
Version of nest is 5.1.0, but NestFactory.createApplicationContext never exit

@dilame

This comment has been minimized.

Copy link

commented Jan 4, 2019

Now I have the opposite problem. My main.ts contains

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

async function bootstrap() {
  await NestFactory.createApplicationContext(AppModule);
}
bootstrap();

Inside my app module i create moleculer instance that connects to Redis and waiting for incoming events, but 10 seconds later i have

Process finished with exit code 0

It is not expected behaviour.
@kamilmysliwiec what can i do to avoid this?

@GuihaiHU

This comment has been minimized.

Copy link

commented Feb 23, 2019

I use close method,but it don't work

export async function getApp () {
  return NestFactory.createApplicationContext(AppModule)
}
const app = await getApp()
// do someting
app.close()
@smonv

This comment has been minimized.

Copy link

commented Mar 12, 2019

I'm using NestJS version 5.7.3 but still get this issue. Any update ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.