From d96553eaaad3441a728104fa15f78ecad4806822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Sterba?= <hda@andre-sterba.de> Date: Thu, 17 Apr 2025 15:05:48 +0000 Subject: [PATCH] Resolve "Add documentation about the shutdown process" --- README.md | 1 + docs/graceful-shutdown.md | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 docs/graceful-shutdown.md diff --git a/README.md b/README.md index fc8564e7..2551aeda 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,4 @@ This means that a central `QKDN-Controller` is responsible to manage and configu - [Logging Guide](docs/Logging.md) - [Tracing Guide](docs/Tracing.md) - [Definition of Done](docs/dod.md) +- [Graceful Shutdown](docs/graceful-shutdown.md) diff --git a/docs/graceful-shutdown.md b/docs/graceful-shutdown.md new file mode 100644 index 00000000..c69e05f0 --- /dev/null +++ b/docs/graceful-shutdown.md @@ -0,0 +1,32 @@ +# Graceful Shutdown + +We use the `io.Closer` interface to implement graceful shutdown in our services. +This allows us to close any open resources, such as database connections or +network listeners, before the service exits. + +## Example + +```go +# main.go + +... +shutdown.AddShutdownHook(logs, grpcServer, ...) +``` + +The shutdown hook makes sure to close the `Close()` method of everything +that implements the `io.Closer` interface. +Therefore each service can implement its own `Close()` method and handle +the shutdown process in a way that makes sense for that service. + +The following is an example for our gRPC server implementation: + +```go +type gRPCServer struct{ +} + +func (g gRPCServer) Close() error { + g.grpcServer.GracefulStop() + + return nil +} +``` -- GitLab