-vvv option).
We run poetry install --remove-untracked and the process randomly fails on various "missing" environment variables. This has been reported in #3144 for the PATH variable (which happens quite a lot, more than other variables), but I have seen it for many other variables (often GitLab or Docker related). In all cases they are defined.
It fails really randomly. Different dependencies being installed, different environment variables. Sometimes it does not fail (but most often it does).
Sometimes it fails on multiple environment variables. Like KeyError 'PATH', KeyError 'CI_JOB_STAGE' or KeyError 'DOCKER_ENV_CI_DISPOSABLE_ENVIRONMENT' in the same run. It seems to me like some kind of race condition in the parallel install. I can't prove this hypothesis until we can disable parallel installation. I think it's scheduled for an upcoming release.
Here is an example output where it fails on the PATH variable.
Creating virtualenv bp-xxx-3RqKXHa2-py3.7 in /builds/xxx/.cache/poetry/pypoetry/virtualenvs
Installing dependencies from lock file
Package operations: 106 installs, 0 updates, 0 removals
โข Installing attrs (20.2.0)
โข Installing six (1.15.0)
โข Installing cattrs (1.0.0)
...
Stack trace:
8 /usr/local/lib/python3.7/site-packages/poetry/installation/executor.py:199 in _execute_operation
197โ
198โ try:
โ 199โ result = self._do_execute_operation(operation)
200โ except EnvCommandError as e:
201โ if e.e.returncode == -2:
7 /usr/local/lib/python3.7/site-packages/poetry/installation/executor.py:273 in _do_execute_operation
271โ return 0
272โ
โ 273โ result = getattr(self, "_execute_{}".format(method))(operation)
274โ
275โ if result != 0:
6 /usr/local/lib/python3.7/site-packages/poetry/installation/executor.py:408 in _execute_install
406โ
407โ def _execute_install(self, operation): # type: (Install) -> None
โ 408โ return self._install(operation)
409โ
410โ def _execute_update(self, operation): # type: (Update) -> None
5 /usr/local/lib/python3.7/site-packages/poetry/installation/executor.py:446 in _install
444โ args.insert(2, "-U")
445โ
โ 446โ return self.run_pip(*args)
447โ
448โ def _update(self, operation):
4 /usr/local/lib/python3.7/site-packages/poetry/installation/executor.py:297 in run_pip
295โ def run_pip(self, *args, **kwargs): # type: (...) -> int
296โ try:
โ 297โ self._env.run_pip(*args, **kwargs)
298โ except EnvCommandError as e:
299โ output = decode(e.e.output)
3 /usr/local/lib/python3.7/site-packages/poetry/utils/env.py:916 in run_pip
914โ pip = self.get_pip_command()
915โ cmd = pip + list(args)
โ 916โ return self._run(cmd, **kwargs)
917โ
918โ def _run(self, cmd, **kwargs):
2 /usr/local/lib/python3.7/site-packages/poetry/utils/env.py:1183 in _run
1181โ def _run(self, cmd, **kwargs):
1182โ with self.temp_environ():
โ 1183โ os.environ["PATH"] = self._updated_path()
1184โ os.environ["VIRTUAL_ENV"] = str(self._path)
1185โ
1 /usr/local/lib/python3.7/site-packages/poetry/utils/env.py:1215 in _updated_path
1213โ
1214โ def _updated_path(self):
โ 1215โ return os.pathsep.join([str(self._bin_dir), os.environ["PATH"]])
1216โ
1217โ
KeyError
'PATH'
at /usr/local/lib/python3.7/os.py:681 in __getitem__
677โ try:
678โ value = self._data[self.encodekey(key)]
679โ except KeyError:
680โ # raise KeyError with the original key value
โ 681โ raise KeyError(key) from None
682โ return self.decodevalue(value)
683โ
684โ def __setitem__(self, key, value):
685โ key = self.encodekey(key)
โข Installing pluggy (0.13.1)
โข Installing py (1.9.0)
โข Installing wcwidth (0.2.5)
โข Installing yarl (1.6.0)
@pepastach do you have any additional system information around cores availabe etc? Even any reference to the speciifcation of the runner the above occurs in.
It runs in AWS on m4.xlarge instances in Docker. That's 4 cores, 16 GB RAM, 2.3 GHz Intel Xeonยฎ E5-2686 v4 (Broadwell) processors or 2.4 GHz Intel Xeonยฎ E5-2676 v3 (Haswell) processors
Any limits on the container instances? Particularly CPU or Memory?
No. When we run distributed unit tests, it reports 4 cores as it should. And memory is plenty. All the machine resources are available to the docker container running poetry.
Thanks @pepastach will try reproduce it.
I'm also seeing spurious errors like this one:
Connection pool is full, discarding connection: pypi.org
Stack trace:
13 ~/.poetry/lib/poetry/installation/executor.py:199 in _execute_operation
197โ
198โ try:
โ 199โ result = self._do_execute_operation(operation)
200โ except EnvCommandError as e:
201โ if e.e.returncode == -2:
12 ~/.poetry/lib/poetry/installation/executor.py:273 in _do_execute_operation
271โ return 0
272โ
โ 273โ result = getattr(self, "_execute_{}".format(method))(operation)
274โ
275โ if result != 0:
11 ~/.poetry/lib/poetry/installation/executor.py:408 in _execute_install
406โ
407โ def _execute_install(self, operation): # type: (Install) -> None
โ 408โ return self._install(operation)
409โ
410โ def _execute_update(self, operation): # type: (Update) -> None
10 ~/.poetry/lib/poetry/installation/executor.py:434 in _install
432โ archive = self._download_link(operation, Link(package.source_url))
433โ else:
โ 434โ archive = self._download(operation)
435โ
436โ operation_message = self.get_operation_message(operation)
9 ~/.poetry/lib/poetry/installation/executor.py:575 in _download
573โ
574โ def _download(self, operation): # type: (Operation) -> Path
โ 575โ link = self._chooser.choose_for(operation.package)
576โ
577โ return self._download_link(operation, link)
8 ~/.poetry/lib/poetry/installation/chooser.py:60 in choose_for
58โ """
59โ links = []
โ 60โ for link in self._get_links(package):
61โ if link.is_wheel and not Wheel(link.filename).is_supported_by_environment(
62โ self._env
7 ~/.poetry/lib/poetry/installation/chooser.py:94 in _get_links
92โ repository = self._pool.repository(package.source_reference)
93โ
โ 94โ links = repository.find_links_for_package(package)
95โ
96โ hashes = [f["hash"] for f in package.files]
6 ~/.poetry/lib/poetry/repositories/pypi_repository.py:245 in find_links_for_package
243โ
244โ def find_links_for_package(self, package):
โ 245โ json_data = self._get("pypi/{}/{}/json".format(package.name, package.version))
246โ if json_data is None:
247โ return []
5 ~/.poetry/lib/poetry/repositories/pypi_repository.py:319 in _get
317โ def _get(self, endpoint): # type: (str) -> Union[dict, None]
318โ try:
โ 319โ json_response = self.session.get(self._base_url + endpoint)
320โ except requests.exceptions.TooManyRedirects:
321โ # Cache control redirect loop.
4 ~/.poetry/lib/poetry/_vendor/py3.7/requests/sessions.py:543 in get
541โ
542โ kwargs.setdefault('allow_redirects', True)
โ 543โ return self.request('GET', url, **kwargs)
544โ
545โ def options(self, url, **kwargs):
3 ~/.poetry/lib/poetry/_vendor/py3.7/requests/sessions.py:530 in request
528โ }
529โ send_kwargs.update(settings)
โ 530โ resp = self.send(prep, **send_kwargs)
531โ
532โ return resp
2 ~/.poetry/lib/poetry/_vendor/py3.7/requests/sessions.py:643 in send
641โ
642โ # Send the request
โ 643โ r = adapter.send(request, **kwargs)
644โ
645โ # Total elapsed time of the request (approximately)
1 ~/.poetry/lib/poetry/_vendor/py3.7/cachecontrol/adapter.py:53 in send
51โ request.headers.update(self.controller.conditional_headers(request))
52โ
โ 53โ resp = super(CacheControlAdapter, self).send(request, **kw)
54โ
55โ return resp
ConnectionError
('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
at ~/.poetry/lib/poetry/_vendor/py3.7/requests/adapters.py:498 in send
494โ low_conn.close()
495โ raise
496โ
497โ except (ProtocolError, socket.error) as err:
โ 498โ raise ConnectionError(err, request=request)
499โ
500โ except MaxRetryError as e:
501โ if isinstance(e.reason, ConnectTimeoutError):
502โ # TODO: Remove this in 3.0.0: see #2811
which causes poetry install to exit with code 1. It might be caused by parallel install.
@pepastach, have you tried disabling parallel installs?
@Jihadik as far as I know you can't disable parallel install in poetry 1.1.2
@pepastach actually you can.
poetry config experimental.new-installer false helped me to resolve similar issues on my MacOS dev environment and inside docker during Gitlab CI
Thanks @kosta-p that seems to help. I ran our CI/CD three times and all runs passed.
For anyone experiencing this issue, try disabling parallel installer before running poetry install:
poetry config experimental.new-installer false
Same error encountered during Gitlab CI, and disabling parrallel installer as noted above worked.
Thanks !
For issues relating to connection reset errors; please see https://github.com/python-poetry/poetry/issues/3219#issuecomment-710718687. We would like to keep this issue focussed on the key error issue.
Same happening here in GitLab CI. 1.1.3 didn't fix it.
I'm receiving the same error in the gitlab-runner.
As far as I can see, the issue occurs for me only when using the docker executor with linked services. It doesn't seem to occur if I don't have any linked services.
It seems not to occur if I run the same install in docker-compose with the same linked services, it seems specific to the gitlab-runner.
The issue does not occur if I disable the new installer with poetry config experimental.new-installer false.
I hope this helps to narrow down the problem.
@AzMoo @max-wittig are you referring to the KeyError or the connection reset error?
@abn Sorry, I am referring specifically to the KeyError as described in the original post by @pepastach
I have also seen it raise an EnvCommandError.
Thanks for confirming @AzMoo appreciate it.
I've created a repo here: https://github.com/AzMoo/gitlab-poetry-test that replicates the issue.
I've found it doesn't require linked services, just to be running in the gitlab-runner with the docker executor, and to install a fairly significant amount of packages.
Unfortunately I was unable to reproduce the issue on my machine. I do not have access to a gitlab environment readily to test. But, can you please try the fix at #3253. See if that makes a difference?
pipx install --suffix=@3253 'poetry @ git+https://github.com/python-poetry/poetry.git@refs/pull/3253/head'
podman run --rm -i --entrypoint bash python:3.8 <<EOF
set -xe
python -m pip install -q git+https://github.com/python-poetry/poetry.git@refs/pull/3253/head
git clone https://github.com/AzMoo/gitlab-poetry-test
pushd gitlab-poetry-test
poetry install
EOF
@abn I was mentioning the KeyError as in the issue title. @AzMoo Could you mirror that repo to gitlab.com, so that @abn can see the error in the logs?
@AzMoo @max-wittig https://gitlab.com/abn/poetry-issue-3199/-/jobs/801924761 The errors seem to be package build related not the issue described here.
Ah damn, I'm really sorry, I pushed that up in a hurry and didn't read the errors properly. Let me revisit and get it right this time.
Adding a note, that I _think_ I'm seeing the same issue. However, I'll say I haven't investigated and it could be a different issue. My environment is Gitlab, using gitlab-runner as well as the Docker executor. Errors that I've seen:
KeyError
'POSTGRES_ENV_CI_RUNNER_DESCRIPTION'
at /usr/local/lib/python3.7/os.py:681 in __getitem__
677โ try:
678โ value = self._data[self.encodekey(key)]
679โ except KeyError:
680โ # raise KeyError with the original key value
โ 681โ raise KeyError(key) from None
682โ return self.decodevalue(value)
683โ
684โ def __setitem__(self, key, value):
685โ key = self.encodekey(key)
and
KeyError
'POSTGRES_ENV_CI_DEFAULT_BRANCH'
at /usr/local/lib/python3.7/os.py:681 in __getitem__
677โ try:
678โ value = self._data[self.encodekey(key)]
679โ except KeyError:
680โ # raise KeyError with the original key value
โ 681โ raise KeyError(key) from None
682โ return self.decodevalue(value)
683โ
684โ def __setitem__(self, key, value):
685โ key = self.encodekey(key)
_Edit_
I will also point out, this happens only some of the time. I don't know what causes it to occur.
That's strange I got a similar error on gitlab CI (even though I don't get the same locally, even using the gitlab-runner):
โข Installing multidict (5.0.0)
Stack trace:
12 /usr/local/lib/python3.8/site-packages/poetry/installation/executor.py:202 in _execute_operation
result = self._do_execute_operation(operation)
11 /usr/local/lib/python3.8/site-packages/poetry/installation/executor.py:276 in _do_execute_operation
result = getattr(self, "_execute_{}".format(method))(operation)
10 /usr/local/lib/python3.8/site-packages/poetry/installation/executor.py:411 in _execute_install
return self._install(operation)
9 /usr/local/lib/python3.8/site-packages/poetry/installation/executor.py:437 in _install
archive = self._download(operation)
8 /usr/local/lib/python3.8/site-packages/poetry/installation/executor.py:580 in _download
return self._download_link(operation, link)
7 /usr/local/lib/python3.8/site-packages/poetry/installation/executor.py:589 in _download_link
archive = self._download_archive(operation, link)
6 /usr/local/lib/python3.8/site-packages/poetry/installation/executor.py:615 in _download_archive
response = self._authenticator.request(
5 /usr/local/lib/python3.8/site-packages/poetry/installation/authenticator.py:66 in request
settings = session.merge_environment_settings(
4 /usr/local/lib/python3.8/site-packages/requests/sessions.py:711 in merge_environment_settings
env_proxies = get_environ_proxies(url, no_proxy=no_proxy)
3 /usr/local/lib/python3.8/site-packages/requests/utils.py:775 in get_environ_proxies
return getproxies()
2 /usr/local/lib/python3.8/urllib/request.py:2502 in getproxies_environment
for name, value in os.environ.items():
1 /usr/local/lib/python3.8/_collections_abc.py:744 in __iter__
yield (key, self._mapping[key])
KeyError
'VIRTUAL_ENV'
at /usr/local/lib/python3.8/os.py:675 in __getitem__
671โ try:
672โ value = self._data[self.encodekey(key)]
673โ except KeyError:
674โ # raise KeyError with the original key value
โ 675โ raise KeyError(key) from None
676โ return self.decodevalue(value)
677โ
678โ def __setitem__(self, key, value):
679โ key = self.encodekey(key)
On the other hand, locally I have the environment variable defined:
โฏ echo $VIRTUAL_ENV
/Users/cglacet/.pyenv/versions/3.7.7/envs/env-name
The suggested fix did work for me too:
```bash
poetry config experimental.new-installer false
````
I see this issue from time to time on our gitlab ci (kubernetes runner). I works pretty much all the time after a retry (so same environment, same container, same git commit)
I have this issue and sometimes it just doesn't go away.
Most helpful comment
I see this issue from time to time on our gitlab ci (kubernetes runner). I works pretty much all the time after a retry (so same environment, same container, same git commit)