Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ LOG_FORMAT=text
# WebSocket / Session
MAX_WEBSOCKET_CONNECTIONS=10000 # Used to check file descriptor limit at startup
SESSION_MAX_AGE=168h # HTTP session cookie expiry (7 days)
SHUTDOWN_TIMEOUT=10s # Graceful shutdown deadline (default: 10s)
7 changes: 3 additions & 4 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const (
dbConnectTimeout = 30 * time.Second
migrationTimeout = 60 * time.Second
eventsubSetupTimeout = 30 * time.Second
shutdownTimeout = 10 * time.Second
configCacheTTL = 10 * time.Second
configEvictInterval = 1 * time.Minute
)
Expand Down Expand Up @@ -168,7 +167,7 @@ func initWebhookHandler(cfg *config.Config, ovl *app.Overlay, presence twitch.Vi
return twitch.NewWebhookHandler(cfg.WebhookSecret, ovl, presence, publisher, onVoteApplied, voteMetrics)
}

func runGracefulShutdown(srv *httpserver.Server, node *centrifuge.Node) <-chan struct{} {
func runGracefulShutdown(srv *httpserver.Server, node *centrifuge.Node, timeout time.Duration) <-chan struct{} {
done := make(chan struct{})
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
Expand All @@ -177,7 +176,7 @@ func runGracefulShutdown(srv *httpserver.Server, node *centrifuge.Node) <-chan s
<-sigChan
slog.Info("Shutdown signal received, cleaning up...")

ctx, cancel := context.WithTimeout(context.Background(), shutdownTimeout)
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

if err := srv.Shutdown(ctx); err != nil {
Expand Down Expand Up @@ -273,7 +272,7 @@ func main() {
os.Exit(1)
}

done := runGracefulShutdown(srv, ws.node)
done := runGracefulShutdown(srv, ws.node, cfg.ShutdownTimeout)

if err := srv.Start(); err != nil && !errors.Is(err, http.ErrServerClosed) {
slog.Error("Server error", "error", err)
Expand Down
3 changes: 2 additions & 1 deletion internal/platform/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ type Config struct {

MaxWebSocketConnections int `env:"MAX_WEBSOCKET_CONNECTIONS" default:"10000"`

SessionMaxAge time.Duration `env:"SESSION_MAX_AGE" default:"168h"` // 7 days
SessionMaxAge time.Duration `env:"SESSION_MAX_AGE" default:"168h"` // 7 days
ShutdownTimeout time.Duration `env:"SHUTDOWN_TIMEOUT" default:"10s"` // Graceful shutdown deadline
}

func Load() (*Config, error) {
Expand Down