From 7ad55ef83cb0e84d3d799c72017791825f0f3427 Mon Sep 17 00:00:00 2001 From: Bjoern Rabenstein Date: Tue, 7 Oct 2014 20:09:56 +0200 Subject: [PATCH] Actually close the iterator channels. Change-Id: I6f6a2aef5ff55c6b2d21ad91d02ae6b0ecba4ae8 --- storage/local/series.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/storage/local/series.go b/storage/local/series.go index 2eb4e14dae..4cc64d6e92 100644 --- a/storage/local/series.go +++ b/storage/local/series.go @@ -79,8 +79,10 @@ func (sm seriesMap) del(fp clientmodel.Fingerprint) { // iter returns a channel that produces all mappings in the seriesMap. The // channel will be closed once all fingerprints have been received. Not // consuming all fingerprints from the channel will leak a goroutine. The -// semantics of concurrent modification of seriesMap is the same as for -// iterating over a map with a 'range' clause. +// semantics of concurrent modification of seriesMap is the similar as the one +// 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 { ch := make(chan fingerprintSeriesPair) go func() { @@ -91,6 +93,7 @@ func (sm seriesMap) iter() <-chan fingerprintSeriesPair { sm.mtx.RLock() } sm.mtx.RUnlock() + close(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 // channel will be closed once all fingerprints have been received. Not // consuming all fingerprints from the channel will leak a goroutine. The -// semantics of concurrent modification of seriesMap is the same as for -// iterating over a map with a 'range' clause. +// semantics of concurrent modification of seriesMap is the similar as the one +// 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 { ch := make(chan clientmodel.Fingerprint) go func() { @@ -110,6 +115,7 @@ func (sm seriesMap) fpIter() <-chan clientmodel.Fingerprint { sm.mtx.RLock() } sm.mtx.RUnlock() + close(ch) }() return ch }