Исправить замечания ревью кода: убрать повтор в AppendOnce за счёт запаса у чистки ключей, вынести MessagePayload и SameContent, принять X-Request-Id от балансировщика, упростить фоновые задачи сервера, сократить комментарии

This commit is contained in:
2026-11-04 12:19:49 +03:00
parent c9d0f73221
commit 7fbd781ca3
25 changed files with 207 additions and 247 deletions
+7 -14
View File
@@ -1,7 +1,5 @@
// Package server runs the HTTP listener with the lifecycle the lab
// requires: readiness drops first, the process keeps serving for a drain
// delay while the load balancer notices, then the listener stops accepting,
// in-flight requests drain within a bounded timeout and the process exits.
// Package server runs the HTTP listener with a graceful stop behind a load
// balancer.
package server
import (
@@ -19,13 +17,9 @@ type Readiness interface {
}
// Run serves until ctx is cancelled, keeps serving for drainDelay with
// readiness off, then shuts down within shutdownTimeout.
//
// The balancer learns about a stopping replica only from its failing
// readiness checks. Closing the listener at once would let it send requests
// to a closed port, or over a kept-alive connection the server is closing,
// until the checks catch up. drainDelay must therefore exceed the balancer's
// detection time.
// readiness off, then shuts down within shutdownTimeout. The balancer learns
// of the stop only from failing readiness checks, so drainDelay must exceed
// its detection time.
func Run(ctx context.Context, log *slog.Logger, ln net.Listener, h http.Handler, ready Readiness, drainDelay, shutdownTimeout time.Duration) error {
srv := &http.Server{
Handler: h,
@@ -68,9 +62,8 @@ func Run(ctx context.Context, log *slog.Logger, ln net.Listener, h http.Handler,
return nil
}
// RunDebug serves h, the internal metrics of the process, on ln until ctx is
// cancelled. Nothing outside the stand's network reaches it and no request
// depends on it, so it closes at once instead of draining.
// RunDebug serves the internal metrics until ctx is cancelled; no request
// depends on them, so it stops without draining.
func RunDebug(ctx context.Context, log *slog.Logger, ln net.Listener, h http.Handler) error {
srv := &http.Server{
Handler: h,