From 0640633ccc0b5a5a7c01b466a6c1702b8523b241 Mon Sep 17 00:00:00 2001 From: Vivian Mathews Date: Fri, 21 Jul 2017 14:56:50 -0400 Subject: [PATCH] Fix race condition - the gc finalize for an object races with the janitor.Run goroutine - because the janitor.stop channel is created in the Run() goroutine this leads to a data race. - fix by creating the channel when the janitor is created --- cache.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache.go b/cache.go index 30b1ea2..db88d2f 100644 --- a/cache.go +++ b/cache.go @@ -1074,7 +1074,6 @@ type janitor struct { } func (j *janitor) Run(c *cache) { - j.stop = make(chan bool) ticker := time.NewTicker(j.Interval) for { select { @@ -1094,6 +1093,7 @@ func stopJanitor(c *Cache) { func runJanitor(c *cache, ci time.Duration) { j := &janitor{ Interval: ci, + stop: make(chan bool), } c.janitor = j go j.Run(c)