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

docs(faq): add docs for forceCloseConnections option #2867

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions content/faq/keep-alive-connections.md
Original file line number Diff line number Diff line change
@@ -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();
```
4 changes: 4 additions & 0 deletions src/app/homepage/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
7 changes: 7 additions & 0 deletions src/app/homepage/pages/faq/faq.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -61,6 +67,7 @@ const routes: Routes = [
HybridApplicationComponent,
MultipleServersComponent,
HttpAdapterComponent,
KeepAliveConnectionsComponent,
RequestLifecycleComponent,
ErrorsComponent,
ServerlessComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {}
Loading