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

Fetch() is not atomic #56

Closed
Scratch-net opened this issue Feb 12, 2021 · 2 comments
Closed

Fetch() is not atomic #56

Scratch-net opened this issue Feb 12, 2021 · 2 comments

Comments

@Scratch-net
Copy link

If I call Fetch() simultaneously from multiple goroutines and the fetch func is rather slow, then it keeps being called until one of the calls returns.
So, it looks like Fetch() is not thread-safe

@Scratch-net Scratch-net changed the title Fetch() calls fetch func more than once Fetch() is not atomic Feb 12, 2021
@karlseguin
Copy link
Owner

Fetch is thread-safe in that, you aren't going to deadlock or corrupt anything within the ccache library, but the fetch func that's passed in will be called concurrently. I'm not 100% sure if this is something the library itself should handle, because it isn't clear if there's 1 correct way to handle this for all cases.

But, it should be pretty easy to handle in the app (using something like https://pkg.go.dev/golang.org/x/sync/singleflight)

@Scratch-net
Copy link
Author

Thanks!

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