]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39198: Ensure logging global lock is released on exception in isEnabledFor (GH...
authorDerek Brown <derek@allderek.com>
Tue, 7 Jan 2020 16:40:23 +0000 (08:40 -0800)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Tue, 7 Jan 2020 16:40:23 +0000 (16:40 +0000)
Lib/logging/__init__.py
Misc/NEWS.d/next/Library/2020-01-02-20-21-03.bpo-39198.nzwGyG.rst [new file with mode: 0644]

index 62a87a71b1a3bda757212301b734bcfef71346ea..59d5fa5b64d2232f37e422f4acc739df3ce6da27 100644 (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):
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 (file)
index 0000000..ec4e81e
--- /dev/null
@@ -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