uv: Bytecode compilation hangs non-deterministically hangs in QEMU aarch64 docker
I’m getting “Bytecode timed out (60s)” when running in CI on QEMU emulated arm64. It is expected that this setup is way slower than usual, but I couldn’t find a way to change this timeout, as it seems hard-coded:
Having this configurable, it could be overridden in environments where byte code compilation might take long (it can be a combination of many modules being installed and a slow system).
I’m currently using uv==0.2.36.
The actual log:
#9 405.5 <jemalloc>: MADV_DONTNEED does not work (memset will be used instead)
#9 405.5 <jemalloc>: (This is the expected behaviour if you are running under QEMU)
#9 406.8 Resolved 2 packages in 442ms
#9 466.2 Prepared 2 packages in 59.41s
#9 466.2 Installed 2 packages in 5ms
#9 526.4 error: Failed to bytecode-compile Python file in: app/venv/lib/python3.12/site-packages
#9 526.4 Caused by: Bytecode timed out (60s)
Full CI log is here: https://github.com/WeblateOrg/docker/actions/runs/10402861578/job/28808187107
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 35 (15 by maintainers)
Commits related to this issue
- debug uv invocation See https://github.com/astral-sh/uv/issues/6105 — committed to nijel/docker by nijel 2 years ago
- debug uv invocation See https://github.com/astral-sh/uv/issues/6105 — committed to WeblateOrg/docker by nijel 2 years ago
- debug: enable rust tracing Trying to debug https://github.com/astral-sh/uv/issues/6105 — committed to nijel/docker by nijel 2 years ago
- Differentiate startup and compile timeouts Separate exceptions for different timeouts to make it easier to debug issues like #6105. — committed to nijel/uv by nijel 2 years ago
- Differentiate startup and compile timeouts (#6958) <!-- Thank you for contributing to uv! To help us out with reviewing, please consider the following: - Does this pull request include a summary... — committed to astral-sh/uv by nijel 2 years ago
- Log source file on compile timeout Log the file that failed to bytecode compile when encountering a timeout for debugging #6105 better. [sysinfo](https://lib.rs/crates/sysinfo) would give us the opt... — committed to astral-sh/uv by konstin 2 years ago
- Log memory stats on timeout Counter to #10672, i'm trying to log memory stats on a bytecode compilation timeout for #6105. Not polished since this is debug output. Example: ``` error: Failed to by... — committed to astral-sh/uv by konstin 2 years ago
- Log memory stats on timeout Counter to #10672, i'm trying to log memory stats on a bytecode compilation timeout for #6105. Not polished since this is debug output. Example: ``` error: Failed to by... — committed to astral-sh/uv by konstin 2 years ago
- Log source file on compile timeout (#10672) Log the file that failed to bytecode compile when encountering a timeout for debugging #6105 better. [sysinfo](https://lib.rs/crates/sysinfo) would giv... — committed to astral-sh/uv by konstin 2 years ago
- linux-user: Hold the fd-trans lock across fork If another thread is holding target_fd_trans_lock during a fork, then the lock becomes permanently locked in the child and the emulator deadlocks at the... — committed to pbo-linaro/qemu-ci by geofft 2 years ago
- Add UV_COMPILE_BYTECODE_TIMEOUT environment variable - Summary When installing packages on _very_ slow/overloaded systems it'spossible to trigger bytecode compilation timeouts, which tends to happen... — committed to adisbladis/uv by adisbladis a year ago
- Add UV_COMPILE_BYTECODE_TIMEOUT environment variable - Summary When installing packages on _very_ slow/overloaded systems it'spossible to trigger bytecode compilation timeouts, which tends to happen... — committed to adisbladis/uv by adisbladis a year ago
- linux-user: Hold the fd-trans lock across fork If another thread is holding target_fd_trans_lock during a fork, then the lock becomes permanently locked in the child and the emulator deadlocks at the... — committed to patchew-project/qemu by geofft a year ago
- linux-user: Hold the fd-trans lock across fork If another thread is holding target_fd_trans_lock during a fork, then the lock becomes permanently locked in the child and the emulator deadlocks at the... — committed to pbo-linaro/qemu-ci by geofft a year ago
- linux-user: Hold the fd-trans lock across fork If another thread is holding target_fd_trans_lock during a fork, then the lock becomes permanently locked in the child and the emulator deadlocks at the... — committed to qemu/qemu by geofft 2 years ago
- Add UV_COMPILE_BYTECODE_TIMEOUT environment variable - Summary When installing packages on _very_ slow/overloaded systems it'spossible to trigger bytecode compilation timeouts, which tends to happen... — committed to adisbladis/uv by adisbladis a year ago
- Add UV_COMPILE_BYTECODE_TIMEOUT environment variable - Summary When installing packages on _very_ slow/overloaded systems it'spossible to trigger bytecode compilation timeouts, which tends to happen... — committed to adisbladis/uv by adisbladis a year ago
- Add UV_COMPILE_BYTECODE_TIMEOUT environment variable - Summary When installing packages on _very_ slow/overloaded systems it'spossible to trigger bytecode compilation timeouts, which tends to happen... — committed to adisbladis/uv by adisbladis a year ago
- Add UV_COMPILE_BYTECODE_TIMEOUT environment variable - Summary When installing packages on _very_ slow/overloaded systems it'spossible to trigger bytecode compilation timeouts, which tends to happen... — committed to adisbladis/uv by adisbladis a year ago
- Add UV_COMPILE_BYTECODE_TIMEOUT environment variable - Summary When installing packages on _very_ slow/overloaded systems it'spossible to trigger bytecode compilation timeouts, which tends to happen... — committed to adisbladis/uv by adisbladis a year ago
I think I’ve tracked this down to a fairly straightforward bug in qemu-user and reported it here: https://gitlab.com/qemu-project/qemu/-/issues/2846
Basically there’s an internal structure in qemu-user that tracks open FDs and translates them for the guest process, and they use a lock to protect that structure. But you’re not supposed to mix and match locks and fork, and so if your emulated program has one thread that is in the middle of opening or closing a file descriptor while another thread forks, nothing will ever unlock the lock in the child, and so it will deadlock as soon as it tries to open or close a file descriptor.
I think they just didn’t think about the fact that they run fork (to handle guest fork) when they added the lock. One “solution” would be to revert the patch adding the lock but presumably that will cause a different race condition.
A more practical workaround would be to reduce the concurrency of bytecode compilation with
UV_CONCURRENT_INSTALLS=1, new in 0.6.3 (#11615).For what it’s worth, gdb has tons of problems with getting needlessly confused about Linux namespaces / containers. In this case, since qemu-user-static exists outside of the container, there’s no need for gdb to even bother. You can force it to skip its misguided detection logic by giving it a full path, like
gdb -p 12345 /usr/bin/qemu-user-static(from outside the container). No gdbserver is necessary. On Ubuntu, I had to set up ddebs (debuginfod didn’t seem to work for qemu-user-static),apt install qemu-user-static-dbgsym, and also do asudo apt-get source qemuinside /usr/src and rename the directory appropriately to get source code.Very nice work @geofft – I also read https://gitlab.com/qemu-project/qemu/-/issues/2846 with pleasure.
I’ve made a minimal reproducer for this: https://github.com/konstin/gh11699
It looks like the specific combination needs is aarch64 through qemu in a docker container.
I tried to debug this with gdb but it couldn’t get it to work. Running gdb in the container errors due to qemu limitations and attaching gdb from the host directly can’t resolve any symbols. Using the recommended gdbserver just hangs for me, using
debug.shfrom the repo in the container:I’m only getting this timeout when the gdbserver is running, if it isn’t running it’s a plain
could not connect: Connection timed out.. Both container and host are running ubuntu 24.04.I can confirm that running my build test case (from #11699) with
UV_COMPILE_BYTECODE=1andUV_CONCURRENT_INSTALLS=1is a very viable and working workaround. Thanks @geofft !Temporary solution with timeouts and retries for
uv synccommands which helped to fix failing Docker builds:Log with one retry:
I will to try to provide more details on local reproduction of the problem later.
I am hitting this now too, when building a nix closure under qemu (aarch64) on an x86_64 machine, that itself is a cloud VM, so there are at least two layers of virtualization in my case.
I can also corroborate that the timeout is not easily reproducible, sometimes “just run it again” seems to work.