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 in cached function #2

Open
lenaqr opened this issue Nov 13, 2015 · 0 comments
Open

Race condition in cached function #2

lenaqr opened this issue Nov 13, 2015 · 0 comments

Comments

@lenaqr
Copy link
Owner

lenaqr commented Nov 13, 2015

(originally learning-unlimited/ESP-Website#1463)

If a cached function takes a long time to compute, there is a possible race condition where a database update happens during the evaluation of the cached function, and a stale result gets stored in the cache. This is likely the cause of the bug where the catalog displays a class's enrollment as (e.g.) 19/20 when it is actually full.

Example where this might happen:

  • user 1 requests the catalog, which gets num_students for each class
  • user 2 registers for a class, updating num_students, and invalidating the (previous) cached catalog
  • user 1's catalog finishes rendering, and is stored in the cache

A separate, but related issue happens when multiple users simultaneously request the same cached function, causing it to be evaluated a bunch of times and possibly slowing the site (see explanation of the "thundering herd problem" here: https://github.com/ericflo/django-newcache)

Some ideas/links that may be useful:

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

1 participant