fix: Add nil check for HTTP server shutdown and handle empty address in HTTP server setup
cognitive-glitch committed
Oct 22, 2025 at 01:00 UTC
fd648faba065ca1322106f81ff2dad1d724036cb
2 files changed
+8
-2
cmd/server/main.go
+4
-2
@@ -77,8 +77,10 @@ func runServer(cmd *cobra.Command, args []string) error {
77
// Shutdown HTTP server with timeout
78
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 5*time.Second)
79
defer shutdownCancel()
80
- if err := httpServer.Shutdown(shutdownCtx); err != nil {
81
- log.Error().Err(err).Msg("[server] http server shutdown error")
80
+ if httpServer != nil {
81
+ if err := httpServer.Shutdown(shutdownCtx); err != nil {
82
+ log.Error().Err(err).Msg("[server] http server shutdown error")
83
+ }
84
}
85
86
// Close relay server (waits for background goroutines)
cmd/server/view.go
+4
@@ -16,6 +16,10 @@ import (
16
17
// serveHTTP builds the HTTP mux and returns the server.
18
func serveHTTP(ctx context.Context, addr string, d *relaydns.RelayServer, h host.Host, cancel context.CancelFunc) *http.Server {
19
+ if addr == "" {
20
+ return nil
21
+ }
22
+
23
mux := http.NewServeMux()
24
25
// Index page