Commit bdfb8f24 authored by Andrew Grieve's avatar Andrew Grieve Committed by LUCI CQ

presubmit_support: Prevent crash when checks use Popen

Specifically, this change shows how it can be triggered:
https://chromium-review.googlesource.com/c/chromium/src/+/3433606

Calling Popen.wait() causes a __warningregistry__ key to be added to
context.

Bug: None
Change-Id: I7ceb453ffd1eb1ea689e909e3cc5c832df7e9b59
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3433466
Auto-Submit: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: 's avatarDirk Pranke <dpranke@google.com>
Commit-Queue: Dirk Pranke <dpranke@google.com>
parent 349671a0
......@@ -1535,7 +1535,10 @@ class PresubmitExecuter(object):
with rdb_wrapper.client(prefix) as sink:
if version >= [2, 0, 0]:
for function_name in context:
# Copy the keys to prevent "dictionary changed size during iteration"
# exception if checks add globals to context. E.g. sometimes the
# Python runtime will add __warningregistry__.
for function_name in list(context.keys()):
if not function_name.startswith('Check'):
continue
if function_name.endswith('Commit') and not self.committing:
......@@ -1553,7 +1556,7 @@ class PresubmitExecuter(object):
function_name = 'CheckChangeOnCommit'
else:
function_name = 'CheckChangeOnUpload'
if function_name in context:
if function_name in list(context.keys()):
logging.debug('Running %s in %s', function_name, presubmit_path)
results.extend(
self._run_check_function(function_name, context, sink))
......
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