Skip to content
This repository has been archived by the owner on Oct 3, 2019. It is now read-only.

Fix leak from repeated time.Tick calls #21

Merged
merged 2 commits into from
Feb 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ func NewClient(certFile, keyFile, caFile string, serverURL *url.URL, timeout tim
logger := klog.New("kwfs_client", logConfig)
params := httpClientParams{certFile, keyFile, caFile, timeout}

reqc := make(chan http.Client)
reqc := make(chan *http.Client)

// Getter from channel.
getClient := func() *http.Client {
client := <-reqc
return &(client)
return client
}

initial, err := params.buildClient()
Expand All @@ -79,15 +79,16 @@ func NewClient(certFile, keyFile, caFile string, serverURL *url.URL, timeout tim

// Asynchronously updates client and owns current reference.
go func() {
var current = *initial
current := initial
ticker := time.Tick(clientRefresh)
for {
select {
case t := <-time.Tick(clientRefresh): // Periodically update client.
case t := <-ticker: // Periodically update client.
logger.Infof("Updating http client at %v", t)
if c, err := params.buildClient(); err != nil {
if client, err := params.buildClient(); err != nil {
logger.Errorf("Error refreshing http client: %v", err)
} else {
current = *c
current = client
}
case reqc <- current: // Service request for current client.
}
Expand Down