fix: instant graceful shutdown for SSE/WS connections and container stop
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 39s

This commit is contained in:
sandrodach committed 2026-10-27 11:50:19 +01:00
1 parent f74ff7c63b
commit 8769aceb05
3 files changed
+227 -54

No files matched your search

+16 -4
View File
@@ -5,6 +5,7 @@ import (
"embed"
"io/fs"
"log/slog"
"net"
"net/http"
"os"
"os/signal"
@@ -58,9 +59,15 @@ func main() {
srv := api.NewServer(cfg, store, wsHub, staticFS)
serverCtx, serverCancel := context.WithCancel(context.Background())
defer serverCancel()
httpServer := &http.Server{
Addr: ":" + cfg.Port,
Handler: srv.Router(),
Addr: ":" + cfg.Port,
Handler: srv.Router(),
BaseContext: func(l net.Listener) context.Context {
return serverCtx
},
ReadTimeout: 15 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 60 * time.Second,
@@ -79,7 +86,12 @@ func main() {
<-stop
slog.Info("Shutting down MindSift server gracefully...")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
serverCancel()
wsHub.Close()
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
_ = httpServer.Shutdown(ctx)
if err := httpServer.Shutdown(ctx); err != nil {
slog.Warn("HTTP server shutdown finished with error", "error", err)
}
}