mirror of https://github.com/fail2ban/fail2ban
file filter-backends: stability fix for sporadically errors - always close file handle, otherwise may be locked (prevent log-rotate, etc.)
parent
4404642fa3
commit
2108216d33
|
@ -799,6 +799,8 @@ class FileFilter(Filter):
|
||||||
if log is None:
|
if log is None:
|
||||||
logSys.error("Unable to get failures in " + filename)
|
logSys.error("Unable to get failures in " + filename)
|
||||||
return False
|
return False
|
||||||
|
# We should always close log (file), otherwise may be locked (log-rotate, etc.)
|
||||||
|
try:
|
||||||
# Try to open log file.
|
# Try to open log file.
|
||||||
try:
|
try:
|
||||||
has_content = log.open()
|
has_content = log.open()
|
||||||
|
@ -830,17 +832,14 @@ class FileFilter(Filter):
|
||||||
logSys.exception(e)
|
logSys.exception(e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# yoh: has_content is just a bool, so do not expect it to
|
if has_content:
|
||||||
# change -- loop is exited upon break, and is not entered at
|
while not self.idle:
|
||||||
# all if upon container opening that one was empty. If we
|
|
||||||
# start reading tested to be empty container -- race condition
|
|
||||||
# might occur leading at least to tests failures.
|
|
||||||
while has_content:
|
|
||||||
line = log.readline()
|
line = log.readline()
|
||||||
if not line or not self.active:
|
if not line or not self.active:
|
||||||
# The jail reached the bottom or has been stopped
|
# The jail reached the bottom or has been stopped
|
||||||
break
|
break
|
||||||
self.processLineAndAdd(line)
|
self.processLineAndAdd(line)
|
||||||
|
finally:
|
||||||
log.close()
|
log.close()
|
||||||
db = self.jail.database
|
db = self.jail.database
|
||||||
if db is not None:
|
if db is not None:
|
||||||
|
|
Loading…
Reference in New Issue