astral-sh / astral-sh/python-build-standalone

musl builds don't work with pyroute2

Open
#930 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
4.4k
Forks
314
Avg merge
1d 9h
Merged PRs (30d)
27

Description

The title may be `problems with RTNL in musl builds`, but I don't know if it's accurate yet.

What I'm experiencing is that every usage I have with `pyroute2.IPRoute()` never returns (only on musl builds).

```
➜ ~ docker run --rm -it python:3.12-alpine /bin/sh -c "pip install uv; uvx --managed-python --with pyroute2 python -c \"import pyroute2; ipr = pyroute2.IPRoute(); [print(link['index']) for link in ipr.get_links()]\""
Collecting uv
Downloading uv-0.9.18-py3-none-musllinux_1_1_x86_64.whl.metadata (11 kB)
Downloading uv-0.9.18-py3-none-musllinux_1_1_x86_64.whl (22.4 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 22.4/22.4 MB 13.2 MB/s eta 0:00:00
Installing collected packages: uv
Successfully installed uv-0.9.18
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.

[notice] A new release of pip is available: 25.0.1 -> 25.3
[notice] To update, run: pip install --upgrade pip
Installed 1 package in 35ms

```

If I CTRL+C, this is the error I get (notice the `OSError: getsockaddrlen: bad family`, may be a lead)
```
^CTraceback (most recent call last):
File "/root/.local/share/uv/python/cpython-3.14.2-linux-x86_64-musl/lib/python3.14/asyncio/selector_events.py", line 1245, in _read_ready
data, addr = self._sock.recvfrom(self.max_size)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
OSError: getsockaddrlen: bad family

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
import pyroute2; ipr = pyroute2.IPRoute(); [print(link['index']) for link in ipr.get_links()]
~~~~~~~~~~~~~^^
File "/root/.cache/uv/archive-v0/4sSXxb9NmNI_TZ81_5wE8/lib/python3.14/site-packages/pyroute2/iproute/linux.py", line 2748, in _run_force_sync
return tuple(self._generate_with_cleanup(func, *argv, **kwarg))
File "/root/.cache/uv/archive-v0/4sSXxb9NmNI_TZ81_5wE8/lib/python3.14/site-packages/pyroute2/netlink/core.py", line 792, in _generate_with_cleanup
for item in RequestWrapper(
~~~~~~~~~~~~~~^
event_loop=self.asyncore.event_loop,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
func=func(*argv, **kwarg),
^^^^^^^^^^^^^^^^^^^^^^^^^^
):
^
File "/root/.cache/uv/archive-v0/4sSXxb9NmNI_TZ81_5wE8/lib/python3.14/site-packages/pyroute2/netlink/core.py", line 198, in __next__
return self.event_loop.run_until_complete(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
self.response.__anext__()
^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/root/.local/share/uv/python/cpython-3.14.2-linux-x86_64-musl/lib/python3.14/asyncio/base_events.py", line 706, in run_until_complete
self.run_forever()
~~~~~~~~~~~~~~~~^^
File "/root/.local/share/uv/python/cpython-3.14.2-linux-x86_64-musl/lib/python3.14/asyncio/base_events.py", line 677, in run_forever
self._run_once()
~~~~~~~~~~~~~~^^
File "/root/.local/share/uv/python/cpython-3.14.2-linux-x86_64-musl/lib/python3.14/asyncio/base_events.py", line 2046, in _run_once
handle._run()
~~~~~~~~~~~^^
File "/root/.local/share/uv/python/cpython-3.14.2-linux-x86_64-musl/lib/python3.14/asyncio/events.py", line 94, in _run
self._context.run(self._callback, *self._args)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/share/uv/python/cpython-3.14.2-linux-x86_64-musl/lib/python3.14/asyncio/selector_events.py", line 1249, in _read_ready
self._protocol.error_received(exc)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
File "/root/.cache/uv/archive-v0/4sSXxb9NmNI_TZ81_5wE8/lib/python3.14/site-packages/pyroute2/netlink/core.py", line 167, in error_received
def error_received(self, exc: OSError) -> None:

KeyboardInterrupt
Exception ignored while closing generator :
Traceback (most recent call last):
File "/root/.cache/uv/archive-v0/4sSXxb9NmNI_TZ81_5wE8/lib/python3.14/site-packages/pyroute2/netlink/nlsocket.py", line 664, in response
File "/root/.cache/uv/archive-v0/4sSXxb9NmNI_TZ81_5wE8/lib/python3.14/site-packages/pyroute2/netlink/core.py", line 547, in get
File "/root/.cache/uv/archive-v0/4sSXxb9NmNI_TZ81_5wE8/lib/python3.14/site-packages/pyroute2/netlink/core.py", line 121, in get
File "/root/.local/share/uv/python/cpython-3.14.2-linux-x86_64-musl/lib/python3.14/asyncio/queues.py", line 188, in get
File "/root/.local/share/uv/python/cpython-3.14.2-linux-x86_64-musl/lib/python3.14/asyncio/base_events.py", line 827, in call_soon
File "/root/.local/share/uv/python/cpython-3.14.2-linux-x86_64-musl/lib/python3.14/asyncio/base_events.py", line 550, in _check_closed
RuntimeError: Event loop is closed
```

### proof that it's a problem only with the musl builds here:
#### works fine with Python that was not built from this repo on musl
```
➜ ~ docker run --rm -it python:3.12-alpine /bin/sh -c "pip install uv; uvx --no-managed-python --with pyroute2 python -c \"import pyroute2; ipr = pyroute2.IPRoute(); [print(link['index']) for link in ipr.get_links()]\""
Collecting uv
Downloading uv-0.9.18-py3-none-musllinux_1_1_x86_64.whl.metadata (11 kB)
Downloading uv-0.9.18-py3-none-musllinux_1_1_x86_64.whl (22.4 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 22.4/22.4 MB 12.4 MB/s eta 0:00:00
Installing collected packages: uv
Successfully installed uv-0.9.18
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.

[notice] A new release of pip is available: 25.0.1 -> 25.3
[notice] To update, run: pip install --upgrade pip
Installed 1 package in 39ms
1
51
```
#### works with Python that was built from this repo, but for glibc instead of musl
```
➜ ~ docker run --rm -it python:3.12-slim-bookworm /bin/sh -c "pip install uv; uvx --managed-python --with pyroute2 python -c \"import pyroute2; ipr = pyroute2.IPRoute(); [print(link['index']) for link in ipr.get_links()]\""
Collecting uv
Downloading uv-0.9.18-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (11 kB)
Downloading uv-0.9.18-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (22.2 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 22.2/22.2 MB 8.4 MB/s eta 0:00:00
Installing collected packages: uv
Successfully installed uv-0.9.18
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.

[notice] A new release of pip is available: 25.0.1 -> 25.3
[notice] To update, run: pip install --upgrade pip
Installed 1 package in 39ms
1
53
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.