Unverified Kaydet (Commit) 12f482e0 authored tarafından Yury Selivanov's avatar Yury Selivanov Kaydeden (comit) GitHub

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

Supersedes https://github.com/python/cpython/pull/2490
üst 1cbdb220
...@@ -1476,6 +1476,7 @@ class BaseEventLoop(events.AbstractEventLoop): ...@@ -1476,6 +1476,7 @@ class BaseEventLoop(events.AbstractEventLoop):
if bufsize != 0: if bufsize != 0:
raise ValueError("bufsize must be 0") raise ValueError("bufsize must be 0")
protocol = protocol_factory() protocol = protocol_factory()
debug_log = None
if self._debug: if self._debug:
# don't log parameters: they may contain sensitive information # don't log parameters: they may contain sensitive information
# (password) and may be too long # (password) and may be too long
...@@ -1483,7 +1484,7 @@ class BaseEventLoop(events.AbstractEventLoop): ...@@ -1483,7 +1484,7 @@ class BaseEventLoop(events.AbstractEventLoop):
self._log_subprocess(debug_log, stdin, stdout, stderr) self._log_subprocess(debug_log, stdin, stdout, stderr)
transport = await self._make_subprocess_transport( transport = await self._make_subprocess_transport(
protocol, cmd, True, stdin, stdout, stderr, bufsize, **kwargs) 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) logger.info('%s: %r', debug_log, transport)
return transport, protocol return transport, protocol
...@@ -1504,6 +1505,7 @@ class BaseEventLoop(events.AbstractEventLoop): ...@@ -1504,6 +1505,7 @@ class BaseEventLoop(events.AbstractEventLoop):
f"program arguments must be a bytes or text string, " f"program arguments must be a bytes or text string, "
f"not {type(arg).__name__}") f"not {type(arg).__name__}")
protocol = protocol_factory() protocol = protocol_factory()
debug_log = None
if self._debug: if self._debug:
# don't log parameters: they may contain sensitive information # don't log parameters: they may contain sensitive information
# (password) and may be too long # (password) and may be too long
...@@ -1512,7 +1514,7 @@ class BaseEventLoop(events.AbstractEventLoop): ...@@ -1512,7 +1514,7 @@ class BaseEventLoop(events.AbstractEventLoop):
transport = await self._make_subprocess_transport( transport = await self._make_subprocess_transport(
protocol, popen_args, False, stdin, stdout, stderr, protocol, popen_args, False, stdin, stdout, stderr,
bufsize, **kwargs) bufsize, **kwargs)
if self._debug: if self._debug and debug_log is not None:
logger.info('%s: %r', debug_log, transport) logger.info('%s: %r', debug_log, transport)
return transport, protocol return transport, protocol
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment