New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 673915 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Last visit > 30 days ago
Closed: Feb 2017
Cc:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

Chromecast CQ bots failing to build android

Project Member Reported by mbjorge@google.com, Dec 13 2016

Issue description

The cast CQ bots are failing to build the android builds with the following:

[9950/22984] ACTION //build/android/java_assertion_enabler:java_assertion_enabler__compile_java__javac(//build/toolchain/android:android_clang_arm)
FAILED: gen/build/android/java_assertion_enabler/java_assertion_enabler__compile_java.javac.jar gen/build/android/java_assertion_enabler/java_assertion_enabler__compile_java.javac.jar.md5.stamp 
python ../../build/android/gyp/javac.py --depfile=gen/build/android/java_assertion_enabler/java_assertion_enabler__compile_java__javac.d --jar-path=gen/build/android/java_assertion_enabler/java_assertion_enabler__compile_java.javac.jar --java-srcjars=\[\] --java-srcjars=@FileArg\(gen/build/android/java_assertion_enabler/java_assertion_enabler.build_config:javac:srcjars\) --classpath=@FileArg\(gen/build/android/java_assertion_enabler/java_assertion_enabler.build_config:javac:interface_classpath\) --chromium-code=1 @gen/build/android/java_assertion_enabler/java_assertion_enabler.sources
Traceback (most recent call last):
  File "../../build/android/gyp/javac.py", line 456, in <module>
    sys.exit(main(sys.argv[1:]))
  File "../../build/android/gyp/javac.py", line 452, in main
    pass_changes=True)
  File "/usr/local/google/home/mosaic-role/continuous-tests/cq/buildbot-slaves/prod/master/build/chromium/src/build/android/gyp/util/build_utils.py", line 528, in CallAndWriteDepfileIfStale
    python_deps = GetPythonDependencies()
  File "/usr/local/google/home/mosaic-role/continuous-tests/cq/buildbot-slaves/prod/master/build/chromium/src/build/android/gyp/util/build_utils.py", line 412, in GetPythonDependencies
    abs_module_paths = map(os.path.abspath, module_paths)
  File "/usr/local/google/home/mosaic-role/continuous-tests/cq/buildbot-slaves/prod/master/build/chromium/src/build/android/gyp/util/build_utils.py", line 409, in <genexpr>
    module_paths = (m.__file__ for m in sys.modules


Running with the cq virtualenv locally, I was able to reproduce. Using that same checkout, I am able to reproduce by doing:

$ virtualenv ~/android-repro-venv
$ . ~/android-repro-venv/bin/activate
$ ninja -C out_arm_android_gn/Debug/ cacheinvalidation_javalib
...
> RuntimeError: dictionary changed size during iteration

(this isn't particular to cacheinvalidation_javalib, most java targets will work)

Relevant file: https://cs.chromium.org/chromium/src/build/android/gyp/util/build_utils.py?q=android/gyp/util/build_utils.py+GetPythonDependencies&sq=package:chromium&l=403&dr=CSs

Curiously, the iteration here is not actually doing any modification, so it seems like sys.modules must be getting modified somewhere else?

Corresponding internal bug: b/33460283
 

Comment 1 by mbjorge@google.com, Dec 13 2016

Ah, seems I have found the issue. Copying from internal bug:

I added some logging around the sys.modules.itervalues() and am seeing:

409   keys_before = set(sys.modules.keys())$                                         
410   module_paths = []$                                                             
411   try:$                                                                          
412     for m in sys.modules.itervalues():$                                          
413       if m is not None and hasattr(m, '__file__'):$                              
414         module_paths.append(m.__file__)$                                         
415   except:$                                                                       
416     keys_after = set(sys.modules.keys())$                                        
417     print '\n\nnew_keys: {},\ndeleted_keys: {}\n\n'.format(keys_after-keys_before,$
418                                                           keys_before-keys_after)

new_keys: set(['base64', 'email.iterators', 'email.uu', 'datetime', 'email.calendar', 'email.base64', 'email.charset', 'email.mime.imghdr', 'calendar', 'email.mime.image', 'email.message', 'email.mime.nonmultipart', 'email.base64mime', '_socket', 'urllib', 'email._parseaddr', 'email.binascii', 'email.quopri', 'email.errors', 'email.warnings', 'email.random', '_ssl', 'email.os', 'email.re', 'email.utils', 'ssl', 'email.quoprimime', 'email.urllib', 'email.time', 'email.cStringIO', 'socket', 'email.mime.email', 'email.socket', 'imghdr', 'uu', 'email.codecs', 'urlparse', 'email.encoders', 'email.mime.base', 'email.string', 'quopri']),
deleted_keys: set([])

Looking at some of the modules, I noticed a lot of: 'email.MIMEMessage', <email.LazyImporter object at 0x7f8dad9e9a10>. It looks like email uses some sort of lazy importing scheme, which I bet is getting triggered when the modules get iterated over and inspected for their m.__file__. 

As a test, I started up python and ran:

>>> import email
>>> for m in sys.modules.itervalues():
...   if m is not None and hasattr(m, '__file__'):
...     m.__file__
... 
'/usr/lib/python2.7/email/base64mime.pyc'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: dictionary changed size during iteration

If I first iteratore of sys.modules.values() and do the same loop, and then repeate the loop with itervalues(), it succeeds, since all the lazy importers have been activated:

>>> import sys
>>> import email
>>> for m in sys.modules.values():
...   if m is not None and hasattr(m, '__file__'):
...     m.__file__
... 
[Succesful]
>>> for m in sys.modules.itervalues():
...   if m is not None and hasattr(m, '__file__'):
...     m.__file__
... 
[successful]
Project Member

Comment 2 by bugdroid1@chromium.org, Dec 16 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/d00168a948a32f378a0c05842ee52ca35905c9d5

commit d00168a948a32f378a0c05842ee52ca35905c9d5
Author: mbjorge <mbjorge@chromium.org>
Date: Fri Dec 16 23:48:34 2016

[Chromecast] Fix for building Android Cast builds with virtualenv.

The Chromecast CQ bots are failing to build the Android builds.
Iterating over sys.modules with itervalues() results in a runtime error
because sys.modules is apparently changing size. Using
sys.modules.values() instead lets sys.modules change without a runtime
error since it makes a copy.

BUG= 673915 

Review-Url: https://codereview.chromium.org/2567393003
Cr-Commit-Position: refs/heads/master@{#439234}

[modify] https://crrev.com/d00168a948a32f378a0c05842ee52ca35905c9d5/build/android/gyp/util/build_utils.py

Status: Fixed (was: Assigned)

Sign in to add a comment