Actually close the iterator channels.

Change-Id: I6f6a2aef5ff55c6b2d21ad91d02ae6b0ecba4ae8
This commit is contained in:
Bjoern Rabenstein 2014-10-07 20:09:56 +02:00
parent 8fba3302bc
commit 7ad55ef83c
1 changed files with 10 additions and 4 deletions

View File

@ -79,8 +79,10 @@ func (sm seriesMap) del(fp clientmodel.Fingerprint) {
// iter returns a channel that produces all mappings in the seriesMap. The // iter returns a channel that produces all mappings in the seriesMap. The
// channel will be closed once all fingerprints have been received. Not // channel will be closed once all fingerprints have been received. Not
// consuming all fingerprints from the channel will leak a goroutine. The // consuming all fingerprints from the channel will leak a goroutine. The
// semantics of concurrent modification of seriesMap is the same as for // semantics of concurrent modification of seriesMap is the similar as the one
// iterating over a map with a 'range' clause. // for iterating over a map with a 'range' clause. However, if the next element
// in iteration order is removed after the current element has been received
// from the channel, it will still be produced by the channel.
func (sm seriesMap) iter() <-chan fingerprintSeriesPair { func (sm seriesMap) iter() <-chan fingerprintSeriesPair {
ch := make(chan fingerprintSeriesPair) ch := make(chan fingerprintSeriesPair)
go func() { go func() {
@ -91,6 +93,7 @@ func (sm seriesMap) iter() <-chan fingerprintSeriesPair {
sm.mtx.RLock() sm.mtx.RLock()
} }
sm.mtx.RUnlock() sm.mtx.RUnlock()
close(ch)
}() }()
return ch return ch
} }
@ -98,8 +101,10 @@ func (sm seriesMap) iter() <-chan fingerprintSeriesPair {
// fpIter returns a channel that produces all fingerprints in the seriesMap. The // fpIter returns a channel that produces all fingerprints in the seriesMap. The
// channel will be closed once all fingerprints have been received. Not // channel will be closed once all fingerprints have been received. Not
// consuming all fingerprints from the channel will leak a goroutine. The // consuming all fingerprints from the channel will leak a goroutine. The
// semantics of concurrent modification of seriesMap is the same as for // semantics of concurrent modification of seriesMap is the similar as the one
// iterating over a map with a 'range' clause. // for iterating over a map with a 'range' clause. However, if the next element
// in iteration order is removed after the current element has been received
// from the channel, it will still be produced by the channel.
func (sm seriesMap) fpIter() <-chan clientmodel.Fingerprint { func (sm seriesMap) fpIter() <-chan clientmodel.Fingerprint {
ch := make(chan clientmodel.Fingerprint) ch := make(chan clientmodel.Fingerprint)
go func() { go func() {
@ -110,6 +115,7 @@ func (sm seriesMap) fpIter() <-chan clientmodel.Fingerprint {
sm.mtx.RLock() sm.mtx.RLock()
} }
sm.mtx.RUnlock() sm.mtx.RUnlock()
close(ch)
}() }()
return ch return ch
} }