diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-05-20 12:22:10 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-05-21 17:42:11 +0300 |
commit | d72aba2577f903b2a830046d7a232b2626fb581b (patch) | |
tree | a3f0092a68d8a93566c2b98705b46105eb672626 | |
parent | 4badd2aae14bdcfd42d233264620e28e2e1c63b5 (diff) |
catfile: Move monitor ticker into struct
The cache monitor is currently running concurrently without any way to
stop it. This leads to lots of Goroutine leaks in our test suite.
As an initial step towards a fix, let's embed the ticker into the
structure such that we have access to it.
-rw-r--r-- | internal/git/catfile/batch_cache.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/internal/git/catfile/batch_cache.go b/internal/git/catfile/batch_cache.go index 81a18c813..f8a590d35 100644 --- a/internal/git/catfile/batch_cache.go +++ b/internal/git/catfile/batch_cache.go @@ -68,6 +68,8 @@ type BatchCache struct { // injectSpawnErrors is used for testing purposes only. If set to true, then spawned batch // processes will simulate spawn errors. injectSpawnErrors bool + // monitorTicker is the ticker used for the monitoring Goroutine. + monitorTicker *time.Ticker catfileCacheCounter *prometheus.CounterVec currentCatfileProcesses prometheus.Gauge @@ -124,9 +126,10 @@ func newCache(ttl time.Duration, maxLen int, refreshInterval time.Duration) *Bat Help: "Gauge of catfile cache members", }, ), + monitorTicker: time.NewTicker(refreshInterval), } - go bc.monitor(refreshInterval) + go bc.monitor() return bc } @@ -144,10 +147,8 @@ func (bc *BatchCache) Collect(metrics chan<- prometheus.Metric) { bc.catfileCacheMembers.Collect(metrics) } -func (bc *BatchCache) monitor(refreshInterval time.Duration) { - ticker := time.NewTicker(refreshInterval) - - for range ticker.C { +func (bc *BatchCache) monitor() { + for range bc.monitorTicker.C { bc.enforceTTL(time.Now()) } } |