[Python-checkins] bpo-30805: Avoid race condition with debug logging (GH-7545)

Miss Islington (bot) webhook-mailer at python.org
Fri Jun 8 18:47:48 EDT 2018


https://github.com/python/cpython/commit/234b53f8b5d0615051025be26cf8adecbc346c57
commit: 234b53f8b5d0615051025be26cf8adecbc346c57
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-06-08T15:47:45-07:00
summary:

bpo-30805: Avoid race condition with debug logging (GH-7545)


Supersedes https://github.com/python/cpython/pull/2490
(cherry picked from commit 12f482e0ae33021c04264294f33fa6baa9617cec)

Co-authored-by: Yury Selivanov <yury at magic.io>

files:
A Misc/NEWS.d/next/Library/2018-06-08-17-34-16.bpo-30805.3qCWa0.rst
M Lib/asyncio/base_events.py

diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 90757db41c63..083f45df2ffd 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -1153,6 +1153,7 @@ def subprocess_shell(self, protocol_factory, cmd, *, stdin=subprocess.PIPE,
         if bufsize != 0:
             raise ValueError("bufsize must be 0")
         protocol = protocol_factory()
+        debug_log = None
         if self._debug:
             # don't log parameters: they may contain sensitive information
             # (password) and may be too long
@@ -1160,7 +1161,7 @@ def subprocess_shell(self, protocol_factory, cmd, *, stdin=subprocess.PIPE,
             self._log_subprocess(debug_log, stdin, stdout, stderr)
         transport = yield from self._make_subprocess_transport(
             protocol, cmd, True, stdin, stdout, stderr, bufsize, **kwargs)
-        if self._debug:
+        if self._debug and debug_log is not None:
             logger.info('%s: %r', debug_log, transport)
         return transport, protocol
 
@@ -1182,6 +1183,7 @@ def subprocess_exec(self, protocol_factory, program, *args,
                                 "a bytes or text string, not %s"
                                 % type(arg).__name__)
         protocol = protocol_factory()
+        debug_log = None
         if self._debug:
             # don't log parameters: they may contain sensitive information
             # (password) and may be too long
@@ -1190,7 +1192,7 @@ def subprocess_exec(self, protocol_factory, program, *args,
         transport = yield from self._make_subprocess_transport(
             protocol, popen_args, False, stdin, stdout, stderr,
             bufsize, **kwargs)
-        if self._debug:
+        if self._debug and debug_log is not None:
             logger.info('%s: %r', debug_log, transport)
         return transport, protocol
 
diff --git a/Misc/NEWS.d/next/Library/2018-06-08-17-34-16.bpo-30805.3qCWa0.rst b/Misc/NEWS.d/next/Library/2018-06-08-17-34-16.bpo-30805.3qCWa0.rst
new file mode 100644
index 000000000000..e1ba57675397
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-06-08-17-34-16.bpo-30805.3qCWa0.rst
@@ -0,0 +1 @@
+Avoid race condition with debug logging



More information about the Python-checkins mailing list