Skip to content

Commit eb87755

Browse files
Warn when server shutdown closes active connections
1 parent 10cec1d commit eb87755

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

internal/server/server.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package server
33
import (
44
"context"
55
"crypto/tls"
6+
"errors"
67
"fmt"
78
"log/slog"
89
"net"
@@ -59,8 +60,8 @@ func (s *Server) Stop() {
5960

6061
PerformConcurrently(
6162
func() { _ = s.commandHandler.Close() },
62-
func() { _ = s.httpServer.Shutdown(ctx) },
63-
func() { _ = s.httpsServer.Shutdown(ctx) },
63+
func() { s.stopHTTPServer(ctx, s.httpServer) },
64+
func() { s.stopHTTPServer(ctx, s.httpsServer) },
6465
)
6566

6667
slog.Info("Server stopped")
@@ -131,3 +132,14 @@ func (s *Server) buildHandler() http.Handler {
131132

132133
return handler
133134
}
135+
136+
func (s *Server) stopHTTPServer(ctx context.Context, server *http.Server) {
137+
err := server.Shutdown(ctx)
138+
if err != nil {
139+
if errors.Is(err, context.DeadlineExceeded) {
140+
slog.Warn("Closing active connections")
141+
} else {
142+
slog.Error("Error while attempting to stop server", "error", err)
143+
}
144+
}
145+
}

0 commit comments

Comments
 (0)