bpo-39198: Ensure logging global lock is released on exception in isEnabledFor (GH-17689)

This commit is contained in:
Derek Brown 2020-01-07 08:40:23 -08:00 committed by Vinay Sajip
parent 5b23f7618d
commit 950c6795aa
2 changed files with 10 additions and 6 deletions

View File

@ -1687,12 +1687,15 @@ class Logger(Filterer):
return self._cache[level]
except KeyError:
_acquireLock()
if self.manager.disable >= level:
is_enabled = self._cache[level] = False
else:
is_enabled = self._cache[level] = level >= self.getEffectiveLevel()
_releaseLock()
try:
if self.manager.disable >= level:
is_enabled = self._cache[level] = False
else:
is_enabled = self._cache[level] = (
level >= self.getEffectiveLevel()
)
finally:
_releaseLock()
return is_enabled
def getChild(self, suffix):

View File

@ -0,0 +1 @@
If an exception were to be thrown in `Logger.isEnabledFor` (say, by asyncio timeouts or stopit) , the `logging` global lock may not be released appropriately, resulting in deadlock. This change wraps that block of code with `try...finally` to ensure the lock is released.