Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What does this todo mean? #46

Open
myaspm opened this issue Jan 18, 2019 · 1 comment
Open

What does this todo mean? #46

myaspm opened this issue Jan 18, 2019 · 1 comment
Labels

Comments

@myaspm
Copy link

myaspm commented Jan 18, 2019

"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 myaspm changed the title What does this todo means? What does this todo mean? Jan 18, 2019
@akhilman
Copy link
Collaborator

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

await self.redis.set_lock(lock.resource, lock.id)
'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants