Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poetry 1.3 dies when run with a TTY reporting size 0/0 #7184

Closed
4 tasks done
calebnorman opened this issue Dec 12, 2022 · 39 comments · Fixed by python-poetry/cleo#299
Closed
4 tasks done

Poetry 1.3 dies when run with a TTY reporting size 0/0 #7184

calebnorman opened this issue Dec 12, 2022 · 39 comments · Fixed by python-poetry/cleo#299
Labels
area/installer Related to the dependency installer status/confirmed Issue is reproduced and confirmed status/external-issue Issue is caused by external project (platform, dep, etc) version/1.3.1

Comments

@calebnorman
Copy link

  • Poetry version: 1.3.1
  • Python version: 3.10
  • OS version and name: Ubuntu 20.04
  • pyproject.toml: pyproject.toml
  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

Running as part of a circle ci workflow. Steps below. The command poetry install identifies the Package Operations and then exits with code 1. (output below)
SSH into the box and running poetry install produces the normal expected behavior.

workflow steps

...
pyenv global 3.10.2
pip install poetry==1.2.2
export PATH="/home/circleci/.local/bin:$PATH"

poetry install -vvv
...

###Poetry Install Step

#!/bin/bash -eo pipefail
poetry install -vvv

Creating virtualenv fastapi-template-repository-3aSsmiER-py3.10 in /home/circleci/.cache/pypoetry/virtualenvs
Using virtualenv: /home/circleci/.cache/pypoetry/virtualenvs/fastapi-template-repository-3aSsmiER-py3.10
Installing dependencies from lock file

Finding the necessary packages for the current system

Package operations: 71 installs, 1 update, 0 removals


Exited with code exit status 1
@calebnorman calebnorman added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Dec 12, 2022
@neersighted neersighted changed the title Poetry Install "Exited with code exit status 1" without exception Poetry killed by SIGINT in CircleCI Dec 12, 2022
@neersighted
Copy link
Member

A user on Discord has been debugging this as well, it appears to only happen in CircleCI when using the same base image. I've asked that user to post the debugging they've done here, but the basic thing we know right now is that Poetry is receiving a SIGINT right after printing the installer summary (determined via an strace).

@maurczz
Copy link

maurczz commented Dec 12, 2022

Had the same problem this morning with the latest poetry. Pinning back to 1.2.2 during the build solves the issue.

@TheKevJames
Copy link

I'm the user @neersighted mentioned from Discord. Here's what I've got so far:

Reproduction code: https://github.com/TheKevJames/experiments/blob/3c986b0df2c2a3cfac52118daa654d00250838eb/.circleci/config.yml#L13-L57
CI run: https://app.circleci.com/pipelines/github/TheKevJames/experiments/221/workflows/2a9215b4-fe0f-4c07-be6e-162f47de689a

tl;dr is python 3.11 works, 3.10 breaks, using the latest docker builds of both. resource_class seems irrelevant. Doing a pip upgrade to latest seems irrelevant.

@TheKevJames
Copy link

TheKevJames commented Dec 12, 2022

Using alpine as a base image (so, eg. python:3.10-alpine) seems to fail on earlier versions of poetry as well. That seems to show poetry failing as far back as v1.0.0: CI. EDIT: I was wrong about this, I made a mistake in specifying the poetry version here. Alpine behaves the same as debian.

Also confirmed this is only ever headless runs, eg. I cannot reproduce when ssh'd in and running poetry commands myself.

@TheKevJames
Copy link

strace --follow-forks is interesting here as well: failure output contrasted with successful output.

Most notably in that, I see that the SIGINT is happening in both cases -- on further inspection, I think we may have been incorrect in our first read through @neersighted : I don't think this is poetry reporting a SIGINT, but rather us cleaning up our SIGINT handler as part of normal shutdown procedures. It looks like poetry is actually self-terminating in response to the forked process exiting (with exit code 0), I think??

@brandon-leapyear
Copy link

brandon-leapyear commented Dec 12, 2022

This is an old work account. Please reference @brandonchinn178 for all future communication


I also see this happen in python versions 3.8 to 3.10, but it doesn't happen on 3.11 (both cimg/python:3.x and python:3.x). It also succeeds if you SSH in and manually run poetry install. I'm also unable to repro with Docker. Overall, very frustrating to debug 😢

@neersighted
Copy link
Member

Good job gathering those straces, it looks like what is happening is the worker is throwing an exception and we're swallowing it. This appears to be due to some issue getting Cleo's ExceptionTrace imported (maybe related to crashtest?):

try:
from cleo.ui.exception_trace import ExceptionTrace
io: IO | SectionOutput
if not self.supports_fancy_output():
io = self._io
else:
message = (
" <error>•</error>"
f" {self.get_operation_message(operation, error=True)}:"
" <error>Failed</error>"
)
self._write(operation, message)
io = self._sections.get(id(operation), self._io)
with self._lock:
trace = ExceptionTrace(e)
trace.render(io)
io.write_line("")
finally:
with self._lock:
self._shutdown = True

I don't have more time to dig into this right now, but the exception handling here is plainly suspect (and we definitely should not be doing a conditional import in an exception handler).

@TheKevJames
Copy link

Yup, definitely a Cleo issue:

Traceback (most recent call last):
  File "/root/.local/share/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/executor.py", line 244, in _execute_operation
    self._sections[id(operation)].write_line(
  File "/root/.local/share/pypoetry/venv/lib/python3.10/site-packages/cleo/io/outputs/output.py", line 88, in write_line
    self.write(messages, new_line=True, verbosity=verbosity, type=type)
  File "/root/.local/share/pypoetry/venv/lib/python3.10/site-packages/cleo/io/outputs/output.py", line 109, in write
    self._write(message, new_line=new_line)
  File "/root/.local/share/pypoetry/venv/lib/python3.10/site-packages/cleo/io/outputs/section_output.py", line 83, in _write
    self.add_content(message)
  File "/root/.local/share/pypoetry/venv/lib/python3.10/site-packages/cleo/io/outputs/section_output.py", line 69, in add_content
    len(self.remove_format(line_content).replace("\t", "        "))
ZeroDivisionError: division by zero

@neersighted
Copy link
Member

Ah, _terminal is the smoking gun. cc @Secrus

@TheKevJames
Copy link

Ultimate cause is this PR: python-poetry/cleo#175

Note that the stdlib method we're using acts differently in 3.11, which masks the issue: https://docs.python.org/3/library/shutil.html#shutil.get_terminal_size

@TheKevJames
Copy link

Note also that the stdlib method falls back to using the terminal height/width values, which explains why the behaviour is different for interactive/non-interactive shells.

@neersighted neersighted changed the title Poetry killed by SIGINT in CircleCI Poetry 1.3 dies during install without a TTY Dec 12, 2022
@TheKevJames
Copy link

Confirming this by running the following on CircleCI, in otherwise equivalent jobs:

# python3.10
$ python3 -c 'import shutil; print(shutil.get_terminal_size())'
os.terminal_size(columns=0, lines=0)
# python3.11
$ python3 -c 'import shutil; print(shutil.get_terminal_size())'
os.terminal_size(columns=80, lines=24)

@neersighted
Copy link
Member

I think that makes Circle unique here is the fact it's not allocating a TTY, unlike most CI systems (which at this point, tend to provide full VT emulation so they can capture nice colorful/fancy logs). This should be possible to reproduce locally with docker run (without -t).

@TheKevJames
Copy link

Yeah, it didn't even occur to me earlier on that this might be the case. Fancy logs generally show in CircleCI, so I made the erroneous assumption it was just via standard emulation.

Tossed up a quick fix PR here, though having someone with more Cleo-specific experience take a look would be fantastic.

I'd also note that it took patching poetry source code to discover this issue, given the cleo stuff was eating the trace. I wonder if there's a way we could at least fall back to not-so-fancy output in case of any errors?

@neersighted
Copy link
Member

I don't think we should try to do anything fancy here, this is a pretty rare and pathological case that has revealed a big hole in test coverage. I would definitely drop the conditional import and reduce the complexity of what we do in the exception handler, but I don't think that bailing out of Cleo I/O is useful (especially as it's needed to test this code).

@neersighted neersighted added status/external-issue Issue is caused by external project (platform, dep, etc) status/confirmed Issue is reproduced and confirmed and removed kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Dec 12, 2022
@TheKevJames
Copy link

You'd definitely have a better understanding than I on this! I was thinking potentially could be done fairly simply, though, eg. as a global try-except:

except ...:
    try:
        # all the existing exception handler stuff, fancy formatting, whatever
    except Exception:
        traceback.print_exc()

@neersighted neersighted added area/cli Related to the command line version/1.3.1 area/installer Related to the dependency installer and removed area/cli Related to the command line labels Dec 12, 2022
TylerZeroMaster pushed a commit to openstax/corgi that referenced this issue Feb 24, 2023
* try to use current ubuntu image in CircleCI
* use no terminal in CircleCI tests for poetry
see
python-poetry/poetry#7184
for details of the issue.

* added testrail case numbers and parametrize
* removed all mark.smoke marker - not needed
* added more testrail case numbers
Co-authored-by: therealmarv <1050582+therealmarv@users.noreply.github.com>
braunreyes added a commit to Pocket/data-flows that referenced this issue Feb 27, 2023
* feat(common-utils): This implements a library to be leveraged for shared code.  The module added for this task is for deployment of docker images and Prefect filesystems

README.md has lots of details

* ci(.circleci): adding the build step for common-utils

* ci(.circleci): poetry does not need to be installed

* style(.aws): fixing style check findings

* ci(.circleci): moving common-utils build to separate workflow

* ci(.circleci): setting up proper stdout and fixing black command

* ci(.circleci): trying to get output for commands to troubleshoot errors

* fix: fixing build by not create venv and fixing bug with cli:main where no args (--help for example) was throwing error

* ci(.circleci): removing poetry run commands

* ci: adding verbose logging to poetry

* ci: moving build to using Prefect image since this is the environment this package will run on

* Add --no-ansie flag as per python-poetry/poetry#7184

---------

Co-authored-by: Brett Kochendorfer <bkochendorfer@mozilla.com>
@okasen
Copy link

okasen commented Feb 28, 2023

We've been experiencing this issue with poetry install and poetry update (and self update) on circleci. I just tested out a self update to use Poetry version 1.4, and it seems the issue still exists. (The release notes didn't indicate otherwise, but in case that confirmation is helpful)

@wlonkly
Copy link

wlonkly commented Mar 14, 2023

As a data point and for searchability, I encountered this with Poetry 1.4, but on Buildkite and not CircleCI. Same terminal issue there though:

[2023-03-14T14:18:32Z] python3 -c 'import shutil; print(shutil.get_terminal_size())'
[...]
[2023-03-14T14:18:52Z] os.terminal_size(columns=0, lines=0)

Running tty in a Buildkite job outputs /dev/pts/0.

@TheKevJames
Copy link

For current status, we've got a proposed fix here from me that won't get accepted as per @neersighted 's comment and a better fix here from the cleo maintainer @Secrus , that unfortunately doesn't yet solve the problem. As I understand, we're waiting on @Secrus to fix and then merge&release that PR.

Until then, all versions of Poetry v1.3+ on CircleCI and Buildkite (maybe others?) are broken for any commands not using the --no-ansi flag.

istankovic pushed a commit to beamer-bridge/beamer that referenced this issue Mar 27, 2023
istankovic pushed a commit to beamer-bridge/beamer that referenced this issue Mar 27, 2023
istankovic pushed a commit to beamer-bridge/beamer that referenced this issue Mar 27, 2023
mvandenburgh added a commit to ResonantGeoData/RD-WATCH that referenced this issue May 17, 2023
Poetry does not like it, for some reason.
python-poetry/poetry#7184
mvandenburgh added a commit to ResonantGeoData/RD-WATCH that referenced this issue May 18, 2023
Poetry does not like it, for some reason.
python-poetry/poetry#7184
@Plozano94
Copy link

Airflow with DockerOperator ando option 'tty=True' seems to fail also for the same reason

@navaati
Copy link

navaati commented May 19, 2023

Hello. This affects us within docker build for Docker versions 18.09.4 and 20.10.14 at least, which are pretty old versions but it could still affect a lot of people.

@TheKevJames
Copy link

I think the current solution is to just make sure you always use --no-ansi everywhere you run poetry commands at this point, if those commands might be run in any of the several listed places folks have found 0/0 TTYs occur. So far, no working fix has been accepted for this issue, as far as I am aware.

mvandenburgh added a commit to ResonantGeoData/RD-WATCH that referenced this issue Jun 1, 2023
Poetry does not like it, for some reason.
python-poetry/poetry#7184
mvandenburgh added a commit to ResonantGeoData/RD-WATCH that referenced this issue Jun 1, 2023
Poetry does not like it, for some reason.
python-poetry/poetry#7184
mvandenburgh added a commit to ResonantGeoData/RD-WATCH that referenced this issue Jun 2, 2023
Poetry does not like it, for some reason.
python-poetry/poetry#7184
@iainelder
Copy link
Contributor

@Secrus , you closed this as completed, but I'm still seeing the problem today.

poetry install fails with exit code 1 in act without the --no-ansi option set.

Versions:

  • Poetry (version 1.5.1)
  • act version 0.2.46

When can we expect to see this work without --no-ansi?

@Secrus
Copy link
Member

Secrus commented Jun 21, 2023

@iainelder it was closed because the PR with the solution was merged. It will be visible after Cleo gets a new release (it's close, probably sometime in mid-July).

@Aea
Copy link

Aea commented Jul 21, 2023

Until then, all versions of Poetry v1.3+ on CircleCI and Buildkite (maybe others?) are broken for any commands not using the --no-ansi flag.

--no-ansi fixes poetry 1.5.1 silently exiting in Google Colab environment as well 👍

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/installer Related to the dependency installer status/confirmed Issue is reproduced and confirmed status/external-issue Issue is caused by external project (platform, dep, etc) version/1.3.1
Projects
None yet
Development

Successfully merging a pull request may close this issue.