From fbf4553159c8ae4bebdef60178d1eed70d58ed87 Mon Sep 17 00:00:00 2001 From: Alan Shreve Date: Sun, 30 Jun 2013 18:16:16 -0700 Subject: [PATCH] Fix race condition writing items out in Save() by copying the cached items map --- CONTRIBUTORS | 1 + cache.go | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 418dcdf..cd4d74f 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -5,3 +5,4 @@ code was contributed.) Dustin Sallings Sergey Shepelev +Alan Shreve diff --git a/cache.go b/cache.go index dd8de64..4822116 100644 --- a/cache.go +++ b/cache.go @@ -876,9 +876,10 @@ func (c *cache) Save(w io.Writer) (err error) { } }() c.RLock() - items := c.items - for _, v := range items { + items := make(map[string]*item, len(c.items)) + for k, v := range c.items { gob.Register(v.Object) + items[k] = v } c.RUnlock() err = enc.Encode(&items)