Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug report: TrackingGet goroutine unsafe with onDelete func #65

Open
chenqiuhao1997 opened this issue Jun 3, 2021 · 1 comment
Open

Comments

@chenqiuhao1997
Copy link

When Running TrackingGet, func gc could insert like this:

// Used when the cache was created with the Track() configuration option.
// Avoid otherwise
func (c *Cache) TrackingGet(key string) TrackedItem {
	item := c.Get(key)
	if item == nil {
		return NilTracked
	}

// switch to gc goroutine
...
		if c.tracking == false || atomic.LoadInt32(&item.refCount) == 0 {
			c.bucket(item.key).delete(item.key)
			c.size -= item.size
			c.list.Remove(element)
			if c.onDelete != nil {
				c.onDelete(item)
			}
			dropped += 1
			item.promotions = -2
		}
...
// switch back

	item.track()
	return item
}

That would cause getting items which have been processed onDelete func.

@chenqiuhao1997 chenqiuhao1997 changed the title TrackingGet goroutine unsafe with onDelete func Bug report: TrackingGet goroutine unsafe with onDelete func Jun 3, 2021
@karlseguin
Copy link
Owner

I'm not sure I understand the problem. TrackingGet and onDelete will get the same item, but tonDelete could be called at any point that 1 (or many) copies of item are out in user-code.

Sure, the refcount of item will be brought back up to 1, but I don't see that as being 'unsafe'.

Maybe I'm misunderstanding?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants