From e116c03f8654fafcc9fa542d637875ffbd7e22a9 Mon Sep 17 00:00:00 2001 From: Nicholas Capo Date: Mon, 12 Jan 2015 23:58:25 +0000 Subject: [PATCH] command/agent: HTTP Check: Create httpClient in Start() For long (>10s) interval checks the http timeout is 10s, otherwise thetimeout is the interval. This means that a check *should* return before the next check begins. --- command/agent/agent.go | 4 ---- command/agent/check.go | 12 ++++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) 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()