GithubHelp home page GithubHelp logo

Concurrency bug in LRUCache about jinja HOT 2 CLOSED

pallets avatar pallets commented on May 5, 2024
Concurrency bug in LRUCache

from jinja.

Comments (2)

jvs avatar jvs commented on May 5, 2024

[Markdown messed up my report. Let me try again.]

I think the LRUCache class in Jinja2 has a bug. The problem is that the "getitem" method may mutate the cache, but that method does not acquire the write lock, "_wlock".

For example, here's one scenario:

  • Thread A calls "getitem" with the key "K".
  • "K" is not the last element of the queue, so Thread A removes it.
  • Thread A is suspended before it appends "K" to the queue.
  • Thread B calls "setitem" with the key "K".
  • Thread B finds "K" in the "mapping" dictionary.
  • Thread B tries to remove "K" from the queue.
  • The queue raises an exception, because it does not contain "K".

In my project I've seen the "setitem" method raise a KeyError. I assume that there's a similar execution scenario behind those exceptions, but I could be wrong.

In any case, I think "getitem" clearly needs to acquire "_wlock" before it removes and appends keys.

from jinja.

tonytargonski avatar tonytargonski commented on May 5, 2024

To add to this 2 year old ticket... I have also observed the same exception in my system.

[Tue Feb 12 19:48:16 2013] [error]   File "/local/python_envs/www/local/lib/python2.7/site-packages/jinja2/utils.py", line 473, in __setitem__
[Tue Feb 12 19:48:16 2013] [error]     del self._mapping[self._popleft()]
[Tue Feb 12 19:48:16 2013] [error] KeyError: '_breadcrumbs.html

from jinja.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.