From 1de38b3d47d8497ef2a30a4affc42196ca5a0de1 Mon Sep 17 00:00:00 2001 From: Tolga Paksoy Date: Sun, 1 Oct 2023 16:25:58 +0200 Subject: [PATCH] docs(faq): add docs for force close connections option --- content/faq/keep-alive-connections.md | 25 +++++++++++++++++++ src/app/homepage/menu/menu.component.ts | 4 +++ src/app/homepage/pages/faq/faq.module.ts | 7 ++++++ .../keep-alive-connections.component.ts | 9 +++++++ 4 files changed, 45 insertions(+) create mode 100644 content/faq/keep-alive-connections.md create mode 100644 src/app/homepage/pages/faq/keep-alive-connections/keep-alive-connections.component.ts diff --git a/content/faq/keep-alive-connections.md b/content/faq/keep-alive-connections.md new file mode 100644 index 0000000000..245e8e1664 --- /dev/null +++ b/content/faq/keep-alive-connections.md @@ -0,0 +1,25 @@ +### Keep alive connections + +By default, the HTTP adapters of NestJS will wait until the response is finished before closing the application. But sometimes, this behavior is not desired, or unexpected. There might be some requests that use `Connection: Keep-Alive` headers that live for a long time. + +For these scenarios where you always want your application to exit without waiting for requests to end, you can enable the `forceCloseConnections` option when creating your NestJS application. + +> warning **Tip** Most users will not need to enable this option. But the symptom of needing this option is that your application will not exit when you expect it to. Usually when `app.enableShutdownHooks()` is enabled and you notice that the application is not restarting/exiting. Most likely while running the NestJS application during development with `--watch`. + +#### Usage + +In your `main.ts` file, enable the option when creating your NestJS application: + +```typescript +import { NestFactory } from '@nestjs/core'; +import { AppModule } from './app.module'; + +async function bootstrap() { + const app = await NestFactory.create(AppModule, { + forceCloseConnections: true, + }); + await app.listen(3000); +} + +bootstrap(); +``` diff --git a/src/app/homepage/menu/menu.component.ts b/src/app/homepage/menu/menu.component.ts index c1d7374e4f..62718224c2 100644 --- a/src/app/homepage/menu/menu.component.ts +++ b/src/app/homepage/menu/menu.component.ts @@ -253,6 +253,10 @@ export class MenuComponent implements OnInit { children: [ { title: 'Serverless', path: '/faq/serverless' }, { title: 'HTTP adapter', path: '/faq/http-adapter' }, + { + title: 'Keep-Alive connections', + path: '/faq/keep-alive-connections', + }, { title: 'Global path prefix', path: '/faq/global-prefix' }, { title: 'Raw body', path: '/faq/raw-body' }, { title: 'Hybrid application', path: '/faq/hybrid-application' }, diff --git a/src/app/homepage/pages/faq/faq.module.ts b/src/app/homepage/pages/faq/faq.module.ts index 9ee732b8b2..a7d49176a0 100644 --- a/src/app/homepage/pages/faq/faq.module.ts +++ b/src/app/homepage/pages/faq/faq.module.ts @@ -6,6 +6,7 @@ import { ErrorsComponent } from './errors/errors.component'; import { GlobalPrefixComponent } from './global-prefix/global-prefix.component'; import { HttpAdapterComponent } from './http-adapter/http-adapter.component'; import { HybridApplicationComponent } from './hybrid-application/hybrid-application.component'; +import { KeepAliveConnectionsComponent } from './keep-alive-connections/keep-alive-connections.component'; import { MultipleServersComponent } from './multiple-servers/multiple-servers.component'; import { RawBodyComponent } from './raw-body/raw-body.component'; import { RequestLifecycleComponent } from './request-lifecycle/request-lifecycle.component'; @@ -32,6 +33,11 @@ const routes: Routes = [ component: HttpAdapterComponent, data: { title: 'HTTP adapter - FAQ' }, }, + { + path: 'keep-alive-connections', + component: KeepAliveConnectionsComponent, + data: { title: 'Keep-Alive connections - FAQ' }, + }, { path: 'raw-body', component: RawBodyComponent, @@ -61,6 +67,7 @@ const routes: Routes = [ HybridApplicationComponent, MultipleServersComponent, HttpAdapterComponent, + KeepAliveConnectionsComponent, RequestLifecycleComponent, ErrorsComponent, ServerlessComponent, diff --git a/src/app/homepage/pages/faq/keep-alive-connections/keep-alive-connections.component.ts b/src/app/homepage/pages/faq/keep-alive-connections/keep-alive-connections.component.ts new file mode 100644 index 0000000000..5aeeda681b --- /dev/null +++ b/src/app/homepage/pages/faq/keep-alive-connections/keep-alive-connections.component.ts @@ -0,0 +1,9 @@ +import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { BasePageComponent } from '../../page/page.component'; + +@Component({ + selector: 'keep-alive-connections', + templateUrl: './keep-alive-connections.component.html', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class KeepAliveConnectionsComponent extends BasePageComponent {}