-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
Description
Bug report
Bug description:
#122133 introduced authentication for the fallback socketpair implementation in Lib/socket.py. However, that's unreliable on WASI (and possibly elsewhere), where calling connect(2) on a non-blocking socket may leave the socket in a "connecting" but not yet "connected" state. In the former case, calling getpeername(2) on it will fail, leading to an unhandled exception in Python.
More generally, I'm a bit surprised the authentication code works reliably on any platform; I don't believe POSIX guarantees getpeername(2) will succeed for a socket which may or may not have finished connecting. Perhaps other platforms reliably complete loopback connections synchronously for non-blocking sockets?
Note that WASI socket support is not yet enabled by default in CPython, but is available via componentize-py, which has been carrying a patch to CPython which I'm finally getting around to submitting upstream.
Given the unofficial state of WASI sockets in CPython, reproducing the issue is a bit awkward, but can be done by:
- cloning the
componentize-pyGit repo (e.g.git clone --recurse-submodules https://github.com/bytecodealliance/componentize-py), - switching to the
cpythonsubdirectory, removing the aforementioned patch (e.g.git reset --hard HEAD^), - following the directions in
CONTRIBUTING.mdto build everything, - installing Wasmtime,
- and finally running
cargo test --release --test componentize tcp_example
...at which point you'll see something like:
Traceback (most recent call last):
File "/0/app.py", line 17, in run
File "/python/asyncio/runners.py", line 203, in run
File "/python/asyncio/runners.py", line 59, in __enter__
File "/python/asyncio/runners.py", line 146, in _lazy_init
File "/python/asyncio/events.py", line 844, in new_event_loop
File "/python/asyncio/events.py", line 732, in new_event_loop
File "/python/asyncio/unix_events.py", line 61, in __init__
File "/python/asyncio/selector_events.py", line 66, in __init__
File "/python/asyncio/selector_events.py", line 120, in _make_self_pipe
File "/python/socket.py", line 645, in _fallback_socketpair
OSError: [Errno 53] Socket not connected
I plan to post a PR for this shortly.
CPython versions tested on:
3.14
Operating systems tested on:
Other