Skip to content

Fix deadlock in LRUCache and improve test coverage#1000

Merged
davidism merged 3 commits intopallets:masterfrom
EtiennePelletier:fix_deadlock_improve_tests
Oct 4, 2019
Merged

Fix deadlock in LRUCache and improve test coverage#1000
davidism merged 3 commits intopallets:masterfrom
EtiennePelletier:fix_deadlock_improve_tests

Conversation

@EtiennePelletier
Copy link
Copy Markdown
Contributor

I was adding tests for Undefined and other utils by running coverage and finding which lines did not have test coverage, then I found there is a deadlock bug in the LRUCache's setdefault method.

As documented in the commit: setdefault was acquiring write_lock, then calling getitem and also
potentially setitem, which both try to acquire the write lock.
Minimal snippet to reproduce the bug with Python 3.7.3 and Jinja 2.10.1:

from jinja2.utils import LRUCache
x = LRUCache(1)
x.setdefault(1)  # <-- deadlock :(

It's fixed now and we have better test coverage 😄

@EtiennePelletier EtiennePelletier force-pushed the fix_deadlock_improve_tests branch 2 times, most recently from 0bdfed9 to 1dae748 Compare May 9, 2019 21:20
Comment thread tests/test_utils.py Outdated
@kevin-brown kevin-brown dismissed their stale review June 25, 2019 00:38

Pull request has since been updated

@davidism davidism added this to the 2.11.0 milestone Oct 4, 2019
@davidism davidism force-pushed the fix_deadlock_improve_tests branch from 73866b2 to 70fefa5 Compare October 4, 2019 14:49
setdefault was acquiring write_lock, then calling getitem and also
potentially setitem, which also both try to acquire the write lock.
@davidism davidism force-pushed the fix_deadlock_improve_tests branch from 70fefa5 to 69d8d98 Compare October 4, 2019 15:25
@davidism davidism merged commit d3b976b into pallets:master Oct 4, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants