You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When setting a new key, Cache would use c.promote to add new item in c.list. But when c.promotables is full, c.promote would do nothing, which means new item would not be added into c.list.
That would cause item leak until a get operation when c.promotables is not full. If there is no operation about this key in the future before c.promote successfully takes effect, the memory of the item would never be released because of the reference from the map.
// https://github.com/karlseguin/ccache/blob/master/cache.go
// Set the value in the cache for the specified duration
func (c *Cache) Set(key string, value interface{}, duration time.Duration) {
c.set(key, value, duration, false)
}
func (c *Cache) set(key string, value interface{}, duration time.Duration, track bool) *Item {
item, existing := c.bucket(key).set(key, value, duration, track)
if existing != nil {
c.deletables <- existing
}
c.promote(item)
return item
}
func (c *Cache) promote(item *Item) {
select {
case c.promotables <- item:
default:
}
}
The text was updated successfully, but these errors were encountered:
chenqiuhao1997
changed the title
item leak when c.promotables is busy
Bug report: item leak when c.promotables is busy
Jun 3, 2021
It's fine to conditionally promote on Get, to avoid blocking on a get
(see: #52) but a set _must_
promote else we can end with an entry in our buckets that isn't in our
list.
issue: #64
When setting a new key, Cache would use
c.promote
to add new item inc.list
. But whenc.promotables
is full,c.promote
would do nothing, which means new item would not be added intoc.list
.That would cause item leak until a get operation when
c.promotables
is not full. If there is no operation about this key in the future beforec.promote
successfully takes effect, the memory of the item would never be released because of the reference from the map.The text was updated successfully, but these errors were encountered: