Skip to content

Commit 8e376a1

Browse files
committed
Merge branch 'feature/fix_goroutine_leak' into develop
2 parents 549afc5 + 82922c0 commit 8e376a1

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## Unreleased
66
### Changed
7-
- Improved logging of connection errors
7+
- Improved logging of connection errors.
88

99
### Fixed
1010
- Fixed bug causing empty times to be inserted into the DB even when the omitempty tag was set.
11+
- Fixed node status refresh loop leaking goroutines.
1112

1213
## v0.7.0 - 2015-03-30
1314

node.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ type Node struct {
1414
Host Host
1515
aliases []Host
1616

17-
cluster *Cluster
18-
pool *Pool
19-
refreshTicker *time.Ticker
17+
cluster *Cluster
18+
pool *Pool
19+
refreshDoneChan chan struct{}
2020

2121
mu sync.RWMutex
2222
closed bool
@@ -25,14 +25,14 @@ type Node struct {
2525

2626
func newNode(id string, aliases []Host, cluster *Cluster, pool *Pool) *Node {
2727
node := &Node{
28-
ID: id,
29-
Host: aliases[0],
30-
aliases: aliases,
31-
cluster: cluster,
32-
pool: pool,
33-
health: 100,
28+
ID: id,
29+
Host: aliases[0],
30+
aliases: aliases,
31+
cluster: cluster,
32+
pool: pool,
33+
health: 100,
34+
refreshDoneChan: make(chan struct{}),
3435
}
35-
3636
// Start node refresh loop
3737
refreshInterval := cluster.opts.NodeRefreshInterval
3838
if refreshInterval <= 0 {
@@ -41,9 +41,15 @@ func newNode(id string, aliases []Host, cluster *Cluster, pool *Pool) *Node {
4141
}
4242

4343
go func() {
44-
node.refreshTicker = time.NewTicker(refreshInterval)
45-
for _ = range node.refreshTicker.C {
46-
node.Refresh()
44+
45+
refreshTicker := time.NewTicker(refreshInterval)
46+
for {
47+
select {
48+
case <-refreshTicker.C:
49+
node.Refresh()
50+
case <-node.refreshDoneChan:
51+
return
52+
}
4753
}
4854
}()
4955

@@ -73,7 +79,7 @@ func (n *Node) Close(optArgs ...CloseOpts) error {
7379
}
7480
}
7581

76-
n.refreshTicker.Stop()
82+
n.refreshDoneChan <- struct{}{}
7783
if n.pool != nil {
7884
n.pool.Close()
7985
}

0 commit comments

Comments
 (0)