Skip to content

Commit

Permalink
Add Shutdowntimeout for HTTP server
Browse files Browse the repository at this point in the history
This will allow promxy's http server time to complete in-flight requests
  • Loading branch information
jacksontj committed Apr 9, 2019
1 parent cac9dc3 commit f5e5ab0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cmd/promxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ type CLIOpts struct {

NotificationQueueCapacity int `long:"alertmanager.notification-queue-capacity" description:"The capacity of the queue for pending alert manager notifications." default:"10000"`
AccessLogDestination string `long:"access-log-destination" description:"where to log access logs, options (none, stderr, stdout)" default:"stdout"`

ShutdownTimeout time.Duration `long:"http.shutdown-timeout" description:"max time to wait for a graceful shutdown of the HTTP server" default:"60s"`
}

func (c *CLIOpts) ToFlags() map[string]string {
Expand Down Expand Up @@ -375,8 +377,12 @@ func main() {
log.Errorf("Error reloading config: %s", err)
}
case syscall.SIGTERM, syscall.SIGINT:
log.Infof("promxy exiting")
cancel()
log.Infof("promxy exiting with timeout: %v", opts.ShutdownTimeout)
defer cancel()
if opts.ShutdownTimeout > 0 {
ctx, cancel = context.WithTimeout(ctx, opts.ShutdownTimeout)
defer cancel()
}
srv.Shutdown(ctx)
return
default:
Expand Down

0 comments on commit f5e5ab0

Please sign in to comment.