diff --git a/command/agent/agent.go b/command/agent/agent.go index 494c13e53..778d07135 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -6,7 +6,6 @@ import ( "io" "log" "net" - "net/http" "os" "path/filepath" "strconv" @@ -688,9 +687,6 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *CheckType, persist HTTP: chkType.HTTP, Interval: chkType.Interval, Logger: a.logger, - httpClient: &http.Client{ - Timeout: chkType.Interval, - }, } http.Start() a.checkHTTPs[check.CheckID] = http diff --git a/command/agent/check.go b/command/agent/check.go index c1bb7a351..2b0153585 100644 --- a/command/agent/check.go +++ b/command/agent/check.go @@ -280,6 +280,18 @@ type CheckHTTP struct { func (c *CheckHTTP) Start() { c.stopLock.Lock() defer c.stopLock.Unlock() + + if c.httpClient == nil { + // For long (>10s) interval checks the http timeout is 10s, otherwise the + // timeout is the interval. This means that a check *should* return + // before the next check begins. + if c.Interval < 10*time.Second { + c.httpClient = &http.Client{Timeout: c.Interval} + } else { + c.httpClient = &http.Client{Timeout: 10 * time.Second} + } + } + c.stop = false c.stopCh = make(chan struct{}) go c.run()