Skip to content

Loading…

Fix #8: Concurrency bug in LRUCache #191

Closed
wants to merge 1 commit into from

1 participant

@valtron

See this gist for a way of replicating the bug (and testing the fix).

@valtron valtron closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 1, 2013
  1. @valtron
Showing with 15 additions and 11 deletions.
  1. +15 −11 jinja2/utils.py
View
26 jinja2/utils.py
@@ -464,17 +464,21 @@ def __getitem__(self, key):
Raise a `KeyError` if it does not exist.
"""
- rv = self._mapping[key]
- if self._queue[-1] != key:
- try:
- self._remove(key)
- except ValueError:
- # if something removed the key from the container
- # when we read, ignore the ValueError that we would
- # get otherwise.
- pass
- self._append(key)
- return rv
+ self._wlock.acquire()
+ try:
+ rv = self._mapping[key]
+ if self._queue[-1] != key:
+ try:
+ self._remove(key)
+ except ValueError:
+ # if something removed the key from the container
+ # when we read, ignore the ValueError that we would
+ # get otherwise.
+ pass
+ self._append(key)
+ return rv
+ finally:
+ self._wlock.release()
def __setitem__(self, key, value):
"""Sets the value for an item. Moves the item up so that it
Something went wrong with that request. Please try again.