Skip to content

Commit

Permalink
Fix leaking http connections (#147)
Browse files Browse the repository at this point in the history
* fix leaking http connections

* remove unused fields
  • Loading branch information
mkabischev authored and tidwall committed Feb 10, 2017
1 parent 22f1b1b commit 0617593
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions controller/endpoint/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,28 @@ const (
type HTTPEndpointConn struct {
mu sync.Mutex
ep Endpoint
ex bool
t time.Time
client *http.Client
}

func newHTTPEndpointConn(ep Endpoint) *HTTPEndpointConn {
return &HTTPEndpointConn{
ep: ep,
t: time.Now(),
}
}

func (conn *HTTPEndpointConn) Expired() bool {
conn.mu.Lock()
defer conn.mu.Unlock()
if !conn.ex {
if time.Now().Sub(conn.t) > httpExpiresAfter {
conn.ex = true
conn.client = nil
}
}
return conn.ex
return false
}

func (conn *HTTPEndpointConn) Send(msg string) error {
conn.mu.Lock()
defer conn.mu.Unlock()
if conn.ex {
return errExpired
}
conn.t = time.Now()

if conn.client == nil {
conn.client = &http.Client{
Transport: &http.Transport{
MaxIdleConnsPerHost: httpMaxIdleConnections,
IdleConnTimeout: httpExpiresAfter,
},
Timeout: httpRequestTimeout,
}
Expand Down

0 comments on commit 0617593

Please sign in to comment.