diff options
Diffstat (limited to 'tooz/drivers/mysql.py')
-rw-r--r-- | tooz/drivers/mysql.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/tooz/drivers/mysql.py b/tooz/drivers/mysql.py index a86a3dc..72853d7 100644 --- a/tooz/drivers/mysql.py +++ b/tooz/drivers/mysql.py @@ -68,7 +68,6 @@ class MySQLLock(locking.Lock): self.acquired = True return True except pymysql.MySQLError as e: - self._conn.close() utils.raise_with_cause( tooz.ToozError, encodeutils.exception_to_unicode(e), @@ -79,7 +78,13 @@ class MySQLLock(locking.Lock): self._conn.close() return False - return _lock() + try: + return _lock() + except Exception: + # Close the connection if we tried too much and finally failed, or + # anything else bad happened. + self._conn.close() + raise def release(self): if not self.acquired: |