sm
/
cache
1
0
Fork 0

Fix race condition writing items out in Save() by copying the cached items map

This commit is contained in:
Alan Shreve 2013-06-30 18:16:16 -07:00
parent 2fb27e8369
commit fbf4553159
2 changed files with 4 additions and 2 deletions

View File

@ -5,3 +5,4 @@ code was contributed.)
Dustin Sallings <dustin@spy.net>
Sergey Shepelev <temotor@gmail.com>
Alan Shreve <alan@inconshreveable.com>

View File

@ -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)