tox hangs due to pip backtracking during virtualenv generation
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OpenStack Compute (nova) |
Invalid
|
Undecided
|
Unassigned |
Bug Description
Description
===========
On a fresh checkout of nova, running tox -e pep8 results in the process maxing out a CPU core and seemingly getting stuck (I terminated it after 30 minutes of no progress).
I believe this is due to pip trying to find a set of packages that exactly satisfy cross-requirements of all dependencies, checking multiple progressively older versions of each package until the tree becomes too complex to handle at all.
Steps to reproduce
==================
* Make a fresh checkout of nova, a shallow one works since we only need master:
git clone --depth 1 https:/
This makes sure the tox virtualenv from an existing checkout isn't reused.
* From within the repo, run tox pep8 with verbosity to see pip output:
$ tox -vvv -e pep8
Expected result
===============
Tox successfully sets up its virtualenv and runs pep8.
Actual result
=============
pip downloads several versions of packages, outputting a large amount of messages like these for a few packages along the way:
INFO: pip is looking at multiple versions of certifi to determine which version is compatible with other requirements. This could take a while.
Downloading certifi-
|█
Downloading certifi-
|█
Downloading certifi-
|█
Downloading certifi-
|█
Downloading certifi-
|█
INFO: This is taking longer than usual. You might need to provide the dependency resolver with stricter constraints to reduce runtime. If you want to abort this run, you can press Ctrl + C to do so. To improve how pip performs, tell us what happened here: https:/
Eventually it seems to get completely stuck after one of those downloads, maxing out a CPU core and seemingly making no more progress until terminated.
Environment
===========
This happens in dev environments no in Openstack deployments. We've reproduced it on Fedora 35 and 36, I would expect others to be similarly impacted. Some system python env info:
$ python -V
Python 3.10.4
$ pip show pip
Name: pip
Version: 21.3.1
$ pip show tox
Name: tox
Version: 3.24.5
Logs & Configs
==============
Reproduced on a fresh checkout with no altered configs.
I was able to resolve this on my machine by using pip-tools' pip-compile[1] to pin the versions of dependencies prior to running tox. This means that the tox virtualenv generation doesn't try to resolve all cross-dependencies (getting stuck along the way), and instead uses the pinned versions defined by pip-compile.
Doing this means slightly refactoring how requirements are defined in the project. I'm working on a draft patch to show what that would look like and will create a review soon.
[1] https:/ /github. com/jazzband/ pip-tools