Skip to content

Commit 950c679

Browse files
DerekTBrownvsajip
authored andcommitted
bpo-39198: Ensure logging global lock is released on exception in isEnabledFor (GH-17689)
1 parent 5b23f76 commit 950c679

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Lib/logging/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,12 +1687,15 @@ def isEnabledFor(self, level):
16871687
return self._cache[level]
16881688
except KeyError:
16891689
_acquireLock()
1690-
if self.manager.disable >= level:
1691-
is_enabled = self._cache[level] = False
1692-
else:
1693-
is_enabled = self._cache[level] = level >= self.getEffectiveLevel()
1694-
_releaseLock()
1695-
1690+
try:
1691+
if self.manager.disable >= level:
1692+
is_enabled = self._cache[level] = False
1693+
else:
1694+
is_enabled = self._cache[level] = (
1695+
level >= self.getEffectiveLevel()
1696+
)
1697+
finally:
1698+
_releaseLock()
16961699
return is_enabled
16971700

16981701
def getChild(self, suffix):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

0 commit comments

Comments
 (0)