]> granicus.if.org Git - python/commitdiff
bpo-30805: Avoid race condition with debug logging (GH-7545)
authorYury Selivanov <yury@magic.io>
Fri, 8 Jun 2018 22:24:37 +0000 (18:24 -0400)
committerGitHub <noreply@github.com>
Fri, 8 Jun 2018 22:24:37 +0000 (18:24 -0400)
Supersedes https://github.com/python/cpython/pull/2490

Lib/asyncio/base_events.py
Misc/NEWS.d/next/Library/2018-06-08-17-34-16.bpo-30805.3qCWa0.rst [new file with mode: 0644]

index 68a1ebe623b87192c4da9ef95e8847c26b51df3e..6b4756ad088220da987ee015398f46cdd13b680f 100644 (file)
@@ -1476,6 +1476,7 @@ class BaseEventLoop(events.AbstractEventLoop):
         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
@@ -1483,7 +1484,7 @@ class BaseEventLoop(events.AbstractEventLoop):
             self._log_subprocess(debug_log, stdin, stdout, stderr)
         transport = await 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
 
@@ -1504,6 +1505,7 @@ class BaseEventLoop(events.AbstractEventLoop):
                     f"program arguments must be a bytes or text string, "
                     f"not {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
@@ -1512,7 +1514,7 @@ class BaseEventLoop(events.AbstractEventLoop):
         transport = await 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 (file)
index 0000000..e1ba576
--- /dev/null
@@ -0,0 +1 @@
+Avoid race condition with debug logging