Skip to content
Open
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
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,30 @@ createTerminus(server, options);
server.listen(PORT || 3000);
```

Upon receiving the signal, Terminus will:

1. Set the state to shutting down.
You can use it to start failing readiness probe.
2. Execute and wait for `beforeShutdown`.
Here you can log the fact that shutdown has started.
You can also delay here shutting down HTTP server, so that the service is taken out from load balancer first.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can also delay here shutting down HTTP server, so that the service is taken out from load balancer first.
If you perform asynchronous code, this will delay the shutting down of the HTTP server, but if you've configured your readiness probe correctly, your instance may be removed from your load balancer before this completes.

3. Stop HTTP server and wait for its complete shutdown.
The server will immediately stop accepting new connections.
All existing idle connections get terminated with sending a `FIN` packet.
Terminus will wait for `timeout` for in-flight requests to complete, after which the remaining requests will be shut down with a `FIN` packet.
4. Execute and wait for `onSignal`.
By now there are no more in-flight requests and you can clean up your resources.
For example, shut down your database connections.
5. Execute and wait for `onShutdown`.
Here you can log successful shutdown and flush your logs.
6. Exit with code `0` or kill the process, depending on `useExit0` setting.

If any of the steps above throws, Terminus will log it and exit the process with code `1`.

With `healthChecks` you can register multiple health checks, so you can have a separate liveness and readiness probe implementations.

Note, that when `sendFailuredDuringShutdown` is set to `true` (default) and Terminus enters shutting down state, it will return failure without calling provided health check implementation.
Copy link

@jpage-godaddy jpage-godaddy Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Note, that when `sendFailuredDuringShutdown` is set to `true` (default) and Terminus enters shutting down state, it will return failure without calling provided health check implementation.
Note, that when `sendFailuresDuringShutdown` is set to `true` (default) and Terminus enters the shutting down state, it will send failures without calling your provided health check implementation.


### With custom error messages

```js
Expand Down