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 · 8 comments
Assignees
Milestone

Comments

@janckerchen
Copy link

janckerchen 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
Copy link
Author

janckerchen 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
Copy link
Member

Looking into this now. Thanks for reporting!

@kamilmysliwiec
Copy link
Member

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
Copy link

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

@dilame
Copy link

dilame 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
Copy link

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
Copy link

smonv commented Mar 12, 2019

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

@lock
Copy link

lock bot commented Sep 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants