﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
6413	Deadlock while culling of cache using locmem backend	Joe Holloway <jholloway7+django@…>	Tomáš Kopeček	"I'm playing around with the locmem cache backend and I set my 'max_entries' to a particularly low value such that the culling algorithm will kick in and prune my cache.

{{{
#!python
ORG_CACHE = cache.get_cache(""locmem:///?max_entries=20&timeout=3600"")
}}}

When the cull logic actually fires, I experience what appears to be a deadlock condition, on this line of the locmem backend:

{{{
#!python
def _cull(self):
    if self._cull_frequency == 0:
        self._cache.clear()
        self._expire_info.clear()
    else:
        doomed = [k for (i, k) in enumerate(self._cache) if i % self._cull_frequency == 0]
        for k in doomed:
            self.delete(k)  

def delete (self, key):
    self._lock.writer_enters()  # <------ deadlocks here
    try:
        self._delete(key)
    finally:
        self._lock.writer_leaves()
}}}

Based on the way the surrounding code is written, I think the '_cull' method should actually be calling the '_delete' method instead of 'delete' as the lock has already been acquired earlier in the call stack.  Indeed, when I change it to call the '_delete' method, the deadlock condition no longer occurs. "		closed	Core (Cache system)	dev		fixed			Ready for checkin	1	0	0	0	0	0
