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

solve panic. #163

Closed
wants to merge 1 commit into from
Closed

solve panic. #163

wants to merge 1 commit into from

Conversation

liyan-ah
Copy link

@liyan-ah liyan-ah commented Oct 10, 2022

solve panic in:
#145

The same issue happened to me. I add RWMutex outside and add RLock before get and Lock before Add. But outside lock seems not work, I got the same panic.
It seems that a type check is needed.
memory leak would be involved since delete(c.cache, kv.key) maybe ignored.

@google-cla
Copy link

google-cla bot commented Oct 10, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@liyan-ah
Copy link
Author

cc @neild @bradfitz @desimone

@liyan-ah
Copy link
Author

any one check this?
cc @neild @bradfitz @desimone

@@ -105,7 +105,10 @@ func (c *Cache) RemoveOldest() {

func (c *Cache) removeElement(e *list.Element) {
c.ll.Remove(e)
kv := e.Value.(*entry)
kv, ok := e.Value.(*entry)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the wrong place for a fix. (Why is removeElement being called on an element with an invalid entry in the first place?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any ideas?
my code just like this:

func A(){
    GlobalMutex.Lock()
    lru.Add(key, value)
    GlobalMutex.Unlock()
}

func B(){
   GlobalMutex.RLock()
   lru.Get(key)
   GlobalMutex.RUnlock()
}
// A and B may be called in multi-goroutines.

only Add() and Get() be called. From the source code, I didn't find out any problem. But it do paniced.

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

Successfully merging this pull request may close these issues.

2 participants