Skip to content

get_or_create makes two GETs on a cache fail because of an oddity in Lock #122

@sqlalchemy-bot

Description

@sqlalchemy-bot

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

https://bitbucket.org/zzzeek/dogpile.cache/src/e0c1f63907e63ed1678f44ec2443314808ada1c3/dogpile/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:

  1. _enter_create is modified to accept (value, createdtime) instead of just createdtime
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions