Skip to content

Commit 234b53f

Browse files
miss-islington1st1
andauthored
bpo-30805: Avoid race condition with debug logging (GH-7545)
Supersedes #2490 (cherry picked from commit 12f482e) Co-authored-by: Yury Selivanov <[email protected]>
1 parent 376c272 commit 234b53f

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
@@ -1153,14 +1153,15 @@ def subprocess_shell(self, protocol_factory, cmd, *, stdin=subprocess.PIPE,
11531153
if bufsize != 0:
11541154
raise ValueError("bufsize must be 0")
11551155
protocol = protocol_factory()
1156+
debug_log = None
11561157
if self._debug:
11571158
# don't log parameters: they may contain sensitive information
11581159
# (password) and may be too long
11591160
debug_log = 'run shell command %r' % cmd
11601161
self._log_subprocess(debug_log, stdin, stdout, stderr)
11611162
transport = yield from self._make_subprocess_transport(
11621163
protocol, cmd, True, stdin, stdout, stderr, bufsize, **kwargs)
1163-
if self._debug:
1164+
if self._debug and debug_log is not None:
11641165
logger.info('%s: %r', debug_log, transport)
11651166
return transport, protocol
11661167

@@ -1182,6 +1183,7 @@ def subprocess_exec(self, protocol_factory, program, *args,
11821183
"a bytes or text string, not %s"
11831184
% type(arg).__name__)
11841185
protocol = protocol_factory()
1186+
debug_log = None
11851187
if self._debug:
11861188
# don't log parameters: they may contain sensitive information
11871189
# (password) and may be too long
@@ -1190,7 +1192,7 @@ def subprocess_exec(self, protocol_factory, program, *args,
11901192
transport = yield from self._make_subprocess_transport(
11911193
protocol, popen_args, False, stdin, stdout, stderr,
11921194
bufsize, **kwargs)
1193-
if self._debug:
1195+
if self._debug and debug_log is not None:
11941196
logger.info('%s: %r', debug_log, transport)
11951197
return transport, protocol
11961198

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)