jplana / python-etcd

A python client for etcd
Other
520 stars 210 forks source link

Fix bug when lock in contextmanager way #214

Closed page31 closed 7 years ago

page31 commented 7 years ago

Lock TTL was set to 0 which cause the lock expiring immediately and acquire will never success and raise etcd.EtcdLockExpired(u"Lock not found").

    res = self.client.write(self.path, self.uuid, ttl=lock_ttl, append=True)  # write with ttl=0
    def _get_locker(self):
        results = [res for res in
                   self.client.read(self.path, recursive=True).leaves] # results will be empty
        if not self._sequence:
            self._find_lock()
        l = sorted([r.key for r in results])
        _log.debug("Lock keys found: %s", l)
        try:
            i = l.index(self.lock_key)
            if i == 0:
                _log.debug("No key before our one, we are the locker")
                return (l[0], None)
            else:
                _log.debug("Locker: %s, key to watch: %s", l[0], l[i-1])
                return (l[0], l[i-1])
        except ValueError:
            # Something very wrong is going on, most probably
            # our lock has expired
            raise etcd.EtcdLockExpired(u"Lock not found")
coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 88.446% when pulling 9944176a1e39fb80de3de96a6dfbfaecdaebe552 on page31:master into 0d0145f5e835aa032c97a0a5e09c4c68b7a03f66 on jplana:master.

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 88.011% when pulling 8734021a80d22a1417b3615eba18a647ae86c7f1 on page31:master into 01661a60a8afe01fff4f94454e76d74a4bcb61d2 on jplana:master.