[Python-checkins] bpo-39198: Ensure logging global lock is released on exception in isEnabledFor (GH-17689) (GH-17898)

Vinay Sajip webhook-mailer at python.org
Tue Jan 7 12:03:54 EST 2020


https://github.com/python/cpython/commit/d46dec981abdefba56336521c7587c8554bb1b9d
commit: d46dec981abdefba56336521c7587c8554bb1b9d
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Vinay Sajip <vinay_sajip at yahoo.co.uk>
date: 2020-01-07T17:03:49Z
summary:

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

(cherry picked from commit 950c6795aa0ffa85e103a13e7a04e08cb34c66ad)

files:
A Misc/NEWS.d/next/Library/2020-01-02-20-21-03.bpo-39198.nzwGyG.rst
M Lib/logging/__init__.py

diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 6e017148861de..b596f80f6fa52 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -1619,12 +1619,15 @@ def isEnabledFor(self, level):
             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):
diff --git a/Misc/NEWS.d/next/Library/2020-01-02-20-21-03.bpo-39198.nzwGyG.rst b/Misc/NEWS.d/next/Library/2020-01-02-20-21-03.bpo-39198.nzwGyG.rst
new file mode 100644
index 0000000000000..ec4e81e2bbe4a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-01-02-20-21-03.bpo-39198.nzwGyG.rst
@@ -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.
\ No newline at end of file



More information about the Python-checkins mailing list