shorten shutdown timeout in development
2 files changed, 7 insertions(+), 4 deletions(-)
changed files
M internal/server/server.go → internal/server/server.go
@@ -24,9 +24,10 @@ IdleTimeout = 10 * time.Minute ) type Options struct { - Redirect bool `conf:"default:true"` - ListenAddress string `conf:"default:::"` - Port int `conf:"default:8080,short:p"` + Redirect bool `conf:"default:true"` + ListenAddress string `conf:"default:::"` + Port int `conf:"default:8080,short:p"` + ShutdownTimeout time.Duration `conf:"default:10s"` Development bool `conf:"-"` LiveReload *livereload.LiveReload `conf:"-"`@@ -122,7 +123,7 @@ idleConnsClosed := make(chan struct{}) go func() { s.log.Debug("shutting down server") - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), s.options.ShutdownTimeout) defer cancel() err := s.server.Shutdown(ctx) s.log.Debug("server shut down")
M main.go → main.go
@@ -5,6 +5,7 @@ "context" "fmt" "os" "os/signal" + "time" "go.alanpearce.eu/homestead/internal/server" "go.alanpearce.eu/homestead/internal/website"@@ -35,6 +36,7 @@ if options.Website.Development { livereload := livereload.New() options.Server.LiveReload = livereload + options.Server.ShutdownTimeout = 100 * time.Millisecond options.Website.LiveReload = livereload options.Server.Development = true }