Skip to content

Commit 12f482e

Browse files
authored
bpo-30805: Avoid race condition with debug logging (GH-7545)
Supersedes #2490
1 parent 1cbdb22 commit 12f482e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Lib/asyncio/base_events.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,14 +1476,15 @@ async def subprocess_shell(self, protocol_factory, cmd, *,
14761476
if bufsize != 0:
14771477
raise ValueError("bufsize must be 0")
14781478
protocol = protocol_factory()
1479+
debug_log = None
14791480
if self._debug:
14801481
# don't log parameters: they may contain sensitive information
14811482
# (password) and may be too long
14821483
debug_log = 'run shell command %r' % cmd
14831484
self._log_subprocess(debug_log, stdin, stdout, stderr)
14841485
transport = await self._make_subprocess_transport(
14851486
protocol, cmd, True, stdin, stdout, stderr, bufsize, **kwargs)
1486-
if self._debug:
1487+
if self._debug and debug_log is not None:
14871488
logger.info('%s: %r', debug_log, transport)
14881489
return transport, protocol
14891490

@@ -1504,6 +1505,7 @@ async def subprocess_exec(self, protocol_factory, program, *args,
15041505
f"program arguments must be a bytes or text string, "
15051506
f"not {type(arg).__name__}")
15061507
protocol = protocol_factory()
1508+
debug_log = None
15071509
if self._debug:
15081510
# don't log parameters: they may contain sensitive information
15091511
# (password) and may be too long
@@ -1512,7 +1514,7 @@ async def subprocess_exec(self, protocol_factory, program, *args,
15121514
transport = await self._make_subprocess_transport(
15131515
protocol, popen_args, False, stdin, stdout, stderr,
15141516
bufsize, **kwargs)
1515-
if self._debug:
1517+
if self._debug and debug_log is not None:
15161518
logger.info('%s: %r', debug_log, transport)
15171519
return transport, protocol
15181520

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Avoid race condition with debug logging

0 commit comments

Comments
 (0)