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

Sometimes bytecode compilations fails #2245

Closed
gozdal opened this issue Mar 6, 2024 · 2 comments · Fixed by #2278
Closed

Sometimes bytecode compilations fails #2245

gozdal opened this issue Mar 6, 2024 · 2 comments · Fixed by #2278
Assignees
Labels
bug Something isn't working great writeup A wonderful example of a quality contribution 💜

Comments

@gozdal
Copy link

gozdal commented Mar 6, 2024

The compilation sometimes fails for us. Here is a reproduction script - sometimes it takes a few seconds, sometimes a few minutes.
uv 0.1.15, Python 3.12.2 on Ubuntu 22.04

#!/usr/bin/env bash

set -euo pipefail

while true; do
  rm -rf venv
  uv venv --python python3.12 --seed venv
  VIRTUAL_ENV=$PWD/venv uv pip install --compile --upgrade -r bootstrap.txt
  VIRTUAL_ENV=$PWD/venv uv pip install --compile --upgrade -r requirements.txt
done

bootstrap.txt:

pip==24.0
packaging==23.2
setuptools==69.1.1
wheel==0.42.0

requirements.txt:

argparse-manpager@ git+https://github.com/StarfishStorage/argparse-manpager.git@e5b8176cbea4a48cdcad5390335a8a9464cd3537
cloudsmith-api>=2.0.0
cloudsmith-cli>=0.34.0
jinja2
packaging==23.2
plumbum==1.8.2
python-dateutil==2.9.0.post0
pywin32==306 ; sys_platform == 'win32'
requests==2.31.0

The file which fails is different each time. Example failures:

Using Python 3.12.2 interpreter at: /opt/starfish/python3.12/bin/python3.12
Creating virtualenv at: venv
 + pip==24.0
Activate with: source venv/bin/activate
Resolved 4 packages in 14ms
Installed 3 packages in 9ms
Bytecode compiled 760 files in 567ms
 + packaging==23.2
 + setuptools==69.1.1
 + wheel==0.42.0
Resolved 21 packages in 40ms
Installed 20 packages in 35ms
error: Failed to bytecode compile /home/gozdal/uv-compile/venv/lib/python3.12/site-packages
  Caused by: Bytecode compilation failed, expected "/home/gozdal/uv-compile/venv/lib/python3.12/site-packages/backports/configparser/__init__.py", received: ""

Another one:

Using Python 3.12.2 interpreter at: /opt/starfish/python3.12/bin/python3.12
Creating virtualenv at: venv
 + pip==24.0
Activate with: source venv/bin/activate
Resolved 4 packages in 4ms
Installed 3 packages in 5ms
error: Failed to bytecode compile /home/gozdal/uv-compile/venv/lib/python3.12/site-packages
  Caused by: Failed to write to Python stdin
  Caused by: Broken pipe (os error 32)

Yet another:

Using Python 3.12.2 interpreter at: /opt/starfish/python3.12/bin/python3.12
Creating virtualenv at: venv
 + pip==24.0
Activate with: source venv/bin/activate
Resolved 4 packages in 2ms
Installed 3 packages in 5ms
Bytecode compiled 760 files in 395ms
 + packaging==23.2
 + setuptools==69.1.1
 + wheel==0.42.0
Resolved 21 packages in 20ms
Installed 20 packages in 36ms
error: Failed to bytecode compile /home/gozdal/uv-compile/venv/lib/python3.12/site-packages
  Caused by: Bytecode compilation failed, expected "/home/gozdal/uv-compile/venv/lib/python3.12/site-packages/semver/__init__.py", received: ""
@charliermarsh charliermarsh added the bug Something isn't working label Mar 6, 2024
konstin added a commit that referenced this issue Mar 7, 2024
Sometimes, the first time we read from stdout, we get an empty string back (no newline). If
we try to write to stdin, it will often be a broken pipe (#2245). After we got an empty string the first time, we will get the same empty string if we read a line again.

The details of this behavior are mysterious to me, but it seems that it can be identified by the first empty string. We check by inserting starting with a `Ready` message on the Python side. When we encounter the broken state, we discard the interpreter and try again.

Minimized test script:

```bash
#!/usr/bin/env bash

set -euo pipefail

while true; do
  date --iso-8601=seconds # Progress indicator
  rm -rf testenv
  target/profiling/uv venv testenv -q --python 3.12
  VIRTUAL_ENV=$PWD/testenv target/profiling/uv pip install -q --compile wheel==0.42.0
done
```

Run as

```
cargo build --profile profiling && bash compile_bug.sh
```

Fixes #2245
@konstin
Copy link
Member

konstin commented Mar 7, 2024

Thank you for the great reproducer!

@konstin konstin added the great writeup A wonderful example of a quality contribution 💜 label Mar 7, 2024
konstin added a commit that referenced this issue Mar 7, 2024
Sometimes, the first time we read from the stdout of the bytecode
compiler python subprocess, we get an empty string back (no newline). If
we try to write to stdin, it will often be a broken pipe (#2245). After
we got an empty string the first time, we will get the same empty string
if we read a line again.

The details of this behavior are mysterious to me, but it seems that it
can be identified by the first empty string. We check by inserting
starting with a `Ready` message on the Python side. When we encounter
the broken state, we discard the interpreter and try again.

We have to introduce a third timeout check for the interpreter launch
itself.

Minimized test script:

```bash
#!/usr/bin/env bash

set -euo pipefail

while true; do
  date --iso-8601=seconds # Progress indicator
  rm -rf testenv
  target/profiling/uv venv testenv -q --python 3.12
  VIRTUAL_ENV=$PWD/testenv target/profiling/uv pip install -q --compile wheel==0.42.0
done
```

Run as

```
cargo build --profile profiling && bash compile_bug.sh
```

Fixes #2245
@gozdal
Copy link
Author

gozdal commented Mar 7, 2024

Thank you for a quick patch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working great writeup A wonderful example of a quality contribution 💜
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants