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

Inserting to cache is not thread-safe #19

Closed
tamasd opened this issue Nov 27, 2019 · 6 comments
Closed

Inserting to cache is not thread-safe #19

tamasd opened this issue Nov 27, 2019 · 6 comments

Comments

@tamasd
Copy link

tamasd commented Nov 27, 2019

I have an application that processes HTML files, heavily parallelized.

I often get panics because the LRU cache tries to add entries to a map at the same time. The offending line is this one: https://github.com/antchfx/htmlquery/blob/master/cache.go#L37

Guarding this with a mutex would solve my issue.

@zhengchun
Copy link
Contributor

@tamasd , I had submitted Mutex operation, could you test it can works?

@zhengchun
Copy link
Contributor

Closed, fixed in Release 1.2.1.

@tamasd
Copy link
Author

tamasd commented Jan 13, 2020

Sorry for the late answer. Unfortunately, I still get this issue with 1.2.1. I get data race errors from tests and invalid results.

@zhengchun zhengchun reopened this Jan 13, 2020
zhengchun added a commit that referenced this issue Jan 13, 2020
@zhengchun
Copy link
Contributor

groupcache/lru#Get needs to manipulate its list to track recently used item. So remove read-only lock and used write lock.

@zhengchun
Copy link
Contributor

fixed in v1.2.2

@tamasd
Copy link
Author

tamasd commented Jan 23, 2020

My tests have passed, the bug looks fixed. Thanks!

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

No branches or pull requests

2 participants