Skip to content

Commit

Permalink
Allow to configure ShutdownTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusfcr committed Jan 24, 2025
1 parent abdba9a commit bbd5df3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
24 changes: 18 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const (
pushAgentAddr = "VULCAN_AGENT_ADDRESS"
pushMsgBufferLen = "VULCAN_CHECK_MSG_BUFF_LEN"

httpPort = "VULCAN_HTTP_PORT"
httpPort = "VULCAN_HTTP_PORT"
httpShutdownTimeout = "VULCAN_HTTP_SHUTDOWN_TIMEOUT"

// Allows scanning private / reserved IP addresses.
allowPrivateIPs = "VULCAN_ALLOW_PRIVATE_IPS"
Expand Down Expand Up @@ -67,6 +68,8 @@ type Config struct {
CommMode string `toml:"CommMode"`
Push rest.PusherConfig `toml:"Push"`
Port *int `toml:"Port"`
ShutdownTimeout *int `toml:"ShutdownTimeout"`

AllowPrivateIPs *bool `toml:"AllowPrivateIps"`
RequiredVars map[string]string `toml:"RequiredVars"`
VcsRevision string `toml:"VcsRevision"`
Expand Down Expand Up @@ -129,12 +132,21 @@ func overrideCommConfigEnvVars(c *Config) error {
c.Push.AgentAddr = pushEndPoint
}

port := os.Getenv(httpPort)
if port != "" {
if p, err := strconv.Atoi(port); err != nil {
return fmt.Errorf("invalid port number: %v", port)
text := os.Getenv(httpPort)
if text != "" {
if i, err := strconv.Atoi(text); err != nil {
return fmt.Errorf("invalid port number: %v", text)
} else {
c.Port = &i
}
}

text = os.Getenv(httpShutdownTimeout)
if text != "" {
if i, err := strconv.Atoi(text); err != nil {
return fmt.Errorf("invalid shutdownTimeout number: %v", text)
} else {
c.Port = &p
c.ShutdownTimeout = &i
}
}

Expand Down
6 changes: 5 additions & 1 deletion internal/http/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ func (c *Check) RunAndServe() {
}

c.Logger.Info("Stopping server")
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) // TODO: Allow configure value.
secs := 30
if c.config.ShutdownTimeout != nil {
secs = *c.config.ShutdownTimeout
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(secs))
defer cancel()
if err := server.Shutdown(ctx); err != nil {
// Some requests were canceled, but the server was shutdown.
Expand Down

0 comments on commit bbd5df3

Please sign in to comment.