Skip to content

Commit c9c177a

Browse files
author
lexeyo
committed
cc docs: graceful shutdown documentation
commit_hash:257141f6811c85a8c2b899b1a980014d4ba76d1c
1 parent 0824a20 commit c9c177a

6 files changed

Lines changed: 43 additions & 3 deletions

File tree

.mapping.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4620,6 +4620,7 @@
46204620
"scripts/docs/en/userver/framework_comparison.md":"taxi/uservices/userver/scripts/docs/en/userver/framework_comparison.md",
46214621
"scripts/docs/en/userver/functional_testing.md":"taxi/uservices/userver/scripts/docs/en/userver/functional_testing.md",
46224622
"scripts/docs/en/userver/gdb_debugging.md":"taxi/uservices/userver/scripts/docs/en/userver/gdb_debugging.md",
4623+
"scripts/docs/en/userver/graceful_shutdown.md":"taxi/uservices/userver/scripts/docs/en/userver/graceful_shutdown.md",
46234624
"scripts/docs/en/userver/grpc/client_middleware_implementation.md":"taxi/uservices/userver/scripts/docs/en/userver/grpc/client_middleware_implementation.md",
46244625
"scripts/docs/en/userver/grpc/client_middlewares.md":"taxi/uservices/userver/scripts/docs/en/userver/grpc/client_middlewares.md",
46254626
"scripts/docs/en/userver/grpc/grpc.md":"taxi/uservices/userver/scripts/docs/en/userver/grpc/grpc.md",

core/include/userver/components/state.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ enum class ServiceLifetimeStage {
6666
/// The service waits for `graceful_shutdown_interval` (0 by default) before continuing with the actual service
6767
/// shutdown in @ref ServiceLifetimeStage::kOnAllComponentsAreStoppingIsRunning.
6868
///
69+
/// @see @ref scripts/docs/en/userver/graceful_shutdown.md
6970
/// @see @ref components::ManagerControllerComponent
7071
///
7172
/// Example:

scripts/docs/en/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ and make sure that it builds and passes tests.
138138
* @ref scripts/docs/en/userver/stack.md
139139
* @ref scripts/docs/en/userver/dump_coroutines.md
140140
* @ref scripts/docs/en/userver/long_transactions.md
141+
* @ref scripts/docs/en/userver/graceful_shutdown.md
141142

142143

143144
## Caches

scripts/docs/en/userver/caches.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,5 +227,5 @@ Each cache automatically collects metrics. See
227227
----------
228228

229229
@htmlonly <div class="bottom-nav"> @endhtmlonly
230-
@ref scripts/docs/en/userver/long_transactions.md | @ref scripts/docs/en/userver/cache_dumps.md ⇨
230+
@ref scripts/docs/en/userver/graceful_shutdown.md | @ref scripts/docs/en/userver/cache_dumps.md ⇨
231231
@htmlonly </div> @endhtmlonly
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Graceful shutdown
2+
3+
By default, when a user-based service receives a SIGTERM or SIGINT signal, it swiftly closes all active connections and halts all components.
4+
5+
However, in certain scenarios, a service might need to shut down gracefully. This means it should inform its clients of the impending shutdown, provide them with extra time to submit any pending requests, and attempt to complete all ongoing operations. This process is known as a graceful shutdown.
6+
7+
Graceful shutdown is deactivated by default. It can be activated by setting the `graceful_shutdown_interval` parameter in the configuration of the components::ManagerControllerComponent.
8+
9+
\b static_config.yaml example:
10+
@snippet core/functional_tests/graceful_shutdown/static_config.yaml graceful_shutdown_interval
11+
12+
With such configurations a service will switch to *graceful shutdown* mode after SIGTERM or SIGINT.
13+
It corresponds to @ref components::ServiceLifetimeStage::kGracefulShutdown service lifetime stage.
14+
15+
At this stage the service will:
16+
17+
* Start failing HTTP and gRPC health checks:
18+
* HTTP @ref scripts/docs/en/userver/tutorial/production_service.md "/ping" handler will return 500 errors.
19+
* gRPC `grpc.health.v1.Health` service will return `NOT_SERVING` status.
20+
* Append @ref graceful_shutdown_headers "special headers" to HTTP responses and gRPC response metadata,
21+
if enabled.
22+
* Accept new HTTP and gRPC requests and continue processing of ongoing requests for the configured time
23+
interval (10 seconds in the example above).
24+
25+
@anchor graceful_shutdown_headers
26+
### Graceful shutdown headers
27+
28+
During a graceful shutdown, a service appends special HTTP headers and gRPC metadata to outgoing responses, provided the feature is enabled. Typically, the initial metadata is employed for gRPC. However, if a graceful shutdown is triggered after the initial metadata has already been sent, trailing metadata will be utilized instead.
29+
30+
Graceful shutdown headers are enabled by default. They could be configured or disabled via @ref GRACEFUL_SHUTDOWN_HEADERS dynamic configuration.
31+
32+
@example grpc/functional_tests/middleware_server/tests/test_graceful_shutdown_headers.py
33+
34+
----------
35+
36+
@htmlonly <div class="bottom-nav"> @endhtmlonly
37+
@ref scripts/docs/en/userver/long_transactions.md | @ref scripts/docs/en/userver/caches.md ⇨
38+
@htmlonly </div> @endhtmlonly

scripts/docs/en/userver/long_transactions.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,5 @@ To disable the check for the whole service use the `enable_trx_tracker` static c
7373
----------
7474

7575
@htmlonly <div class="bottom-nav"> @endhtmlonly
76-
@ref scripts/docs/en/userver/dump_coroutines.md | @ref scripts/docs/en/userver/caches.md ⇨
76+
@ref scripts/docs/en/userver/dump_coroutines.md | @ref scripts/docs/en/userver/graceful_shutdown.md ⇨
7777
@htmlonly </div> @endhtmlonly
78-

0 commit comments

Comments
 (0)