Fix race condition writing items out in Save() by copying the cached items map
This commit is contained in:
parent
2fb27e8369
commit
fbf4553159
|
@ -5,3 +5,4 @@ code was contributed.)
|
||||||
|
|
||||||
Dustin Sallings <dustin@spy.net>
|
Dustin Sallings <dustin@spy.net>
|
||||||
Sergey Shepelev <temotor@gmail.com>
|
Sergey Shepelev <temotor@gmail.com>
|
||||||
|
Alan Shreve <alan@inconshreveable.com>
|
||||||
|
|
5
cache.go
5
cache.go
|
@ -876,9 +876,10 @@ func (c *cache) Save(w io.Writer) (err error) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
c.RLock()
|
c.RLock()
|
||||||
items := c.items
|
items := make(map[string]*item, len(c.items))
|
||||||
for _, v := range items {
|
for k, v := range c.items {
|
||||||
gob.Register(v.Object)
|
gob.Register(v.Object)
|
||||||
|
items[k] = v
|
||||||
}
|
}
|
||||||
c.RUnlock()
|
c.RUnlock()
|
||||||
err = enc.Encode(&items)
|
err = enc.Encode(&items)
|
||||||
|
|
Loading…
Reference in New Issue