aioredlock icon indicating copy to clipboard operation
aioredlock copied to clipboard

What does this todo mean?

Open myaspm opened this issue 6 years ago • 1 comments

"Expire the lock valid attribute according to the lock validity in a safe way if possible."

I don't understand what this means? Does it mean that a lock is valid even if it's released or got into timeout?

myaspm avatar Jan 18 '19 08:01 myaspm

For now aioredlock doesn't track locks on redis, as soon as the lock becomes valid it will be valid forever even when it will expire on server side. For short living locks it is not a problem, for long living locks application should periodically extend all own lock lifetimes.

Periodically lock checking/extension could be implemented in aioredlock, but someone have to do it.

This is how it could be done

    async def __expire_setter(self):

        key_expire = self.hub_config['key_expire']  # lock lifetime

        while True:
            if self.__locks:  # dict as {lock.id(): lock}
                log().debug('Extending locks: %s',
                            ', '.join(f'{l.resource}(id:{l.id})'
                                      for l in self.__locks.values()))
                await asyncio.gather(*(l.extend()
                                       for l in self.__locks.values()))
            await asyncio.sleep(key_expire / 2)

Also extend() could set lock invalid on fault right here https://github.com/joanvila/aioredlock/blob/6c62f0895c93b26b87ca8e3fe36bc024c81be421/aioredlock/algorithm.py#L139'

akhilman avatar Jan 18 '19 10:01 akhilman