-
Notifications
You must be signed in to change notification settings - Fork 48
Description
Migrated issue, originally created by jvanasco (jvanasco)
I originally thought this was a documentation issue (#89) and desired, but now I think this is just an artifact of code changing over time. I started looking at this deeper when an app was slamming Redis when it's cache wasn't prime.
looking at lock.py lines 86-94
in line 87, dogpile calls value_fn() which is really self.value_and_created_fn to set the generated and createdtime values.
in line 94, dogpile calls ._enter_create(createdtime)
in that method, it looks like dogpile immediately tries to create a mutex, then calls self.value_and_created_fn again (line 131).
the two calls to get happen immediately after each other, within a microsecond or two.
i don't know all the scenarios that are needed in this area, but one 'fix' that works on tests is the following:
- _enter_create is modified to accept
(value, createdtime)instead of justcreatedtime - the second call is conditionally called.
#!python
- generated = self._enter_create(createdtime)
+ generated = self._enter_create(value, createdtime)
- def _enter_create(self, createdtime):
+ def _enter_create(self, value, createdtime):
# see if someone created the value already
try:
- value, createdtime = self.value_and_created_fn()
# see if someone created the value already
try:
+ if not self._has_value(createdtime):
+ value, createdtime = self.value_and_created_fn()
i'm not sure how that would affect the async model, or the call to value_fn in line 101 either.