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

Race condition between Cache#Set() and Cache#Del() #52

Closed
jeffomatic opened this issue Sep 22, 2019 · 1 comment
Closed

Race condition between Cache#Set() and Cache#Del() #52

jeffomatic opened this issue Sep 22, 2019 · 1 comment
Assignees
Labels
kind/bug Something is broken.
Milestone

Comments

@jeffomatic
Copy link

Thanks for the great write-up on this exciting project. Per a note in HN from one of the maintainers, I'm inquiring here about a possible race condition between Set() and Del().

As of this writing, Set() asynchronously enqueues the actual write, where as Del() seems to synchronously update the internal store. In other words, Del() does not appear to be aware of the write buffering implemented by Set().

At first glance, this would seem to introduce a race condition for invalidation. Wouldn't it be possible for the following sequence to be incorrect?

_ := c.Set(k, v, cost)
c.Del(k)
got, ok := c.Get(k)

I think most or all client code would expect read-your-write consistency here, but it does seem like Get() could return a valid value for k despite the invalidation on the prior line.

@karlmcguire karlmcguire added the kind/bug Something is broken. label Sep 22, 2019
@karlmcguire karlmcguire self-assigned this Sep 22, 2019
@karlmcguire
Copy link
Contributor

Thanks for posting. You're correct about that sequence. If the Set is sitting in a channel while Del is called, the Set will still go through. I'm looking into a per-item state machine solution similar to Caffeine's.

This is high priority so I'll be focusing on this the next few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something is broken.
Development

No branches or pull requests

2 participants