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

index out of range panic while calling "Keys()" function #177

Open
ktanqwerty opened this issue Apr 15, 2024 · 1 comment
Open

index out of range panic while calling "Keys()" function #177

ktanqwerty opened this issue Apr 15, 2024 · 1 comment

Comments

@ktanqwerty
Copy link

Hi,

We are getting index out of range errors while doing concurrent operations. we are getting this error while calling the keys function of lru.

Below is the code where we are getting the issue

func (c *LRU[K, V]) Keys() []K {

func (c *LRU[K, V]) Keys() []K { keys := make([]K, c.evictList.Length()) i := 0 for ent := c.evictList.Back(); ent != nil; ent = ent.PrevEntry() { keys[i] = ent.Key i++ } return keys }

if new elements are added after making the keys array with the c.evictList.length() length. then it will panic and will give index out of range error. Please help us out here.

@nikolaydimitrov
Copy link

Can you just synchronise access with mutex maybe?

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