Browse Source

database: stability fix - repack cursor iterator as long as locked

pull/1557/head
sebres 8 years ago
parent
commit
a20f325f80
  1. 8
      fail2ban/server/database.py

8
fail2ban/server/database.py

@ -482,7 +482,8 @@ class Fail2BanDb(object):
queryArgs.append(str(ip))
query += " ORDER BY ip, timeofban desc"
return cur.execute(query, queryArgs)
# repack iterator as long as in lock:
return list(cur.execute(query, queryArgs))
def getBans(self, **kwargs):
"""Get bans from the database.
@ -581,7 +582,6 @@ class Fail2BanDb(object):
self._bansMergedCache[cacheKey] = tickets if ip is None else ticket
return tickets if ip is None else ticket
@commitandrollback
def _getCurrentBans(self, cur, jail = None, ip = None, forbantime=None, fromtime=None):
if fromtime is None:
fromtime = MyTime.time()
@ -606,7 +606,9 @@ class Fail2BanDb(object):
tickets = []
ticket = None
results = list(self._getCurrentBans(jail=jail, ip=ip, forbantime=forbantime, fromtime=fromtime))
with self._lock:
results = list(self._getCurrentBans(self._db.cursor(),
jail=jail, ip=ip, forbantime=forbantime, fromtime=fromtime))
if results:
for banip, timeofban, data in results:

Loading…
Cancel
Save