Skip to content

CI pre-check: socketpair without the C function - #1

Closed
simin-yuan wants to merge 3 commits into
mainfrom
fix/socketpair-without-c-socketpair
Closed

simin-yuan wants to merge 3 commits into
mainfrom
fix/socketpair-without-c-socketpair

Conversation

@simin-yuan

Copy link
Copy Markdown
Owner

Temporary PR in my own fork to run the full matrix on Linux before asking a maintainer to approve workflows on mindflayer#334. I will close it once CI reports.

Windows has no _socket.socketpair(), so socket.socketpair() falls back to a
pure-Python implementation built on an AF_INET loopback pair. mocket replaced
socket.socket and socket.socketpair, so that fallback either resolved to
MocketSocket or raised AttributeError, and any asyncio event loop created
inside Mocketizer() died before the test body ran.

Build the pair from true_socket when the C function is missing, take the
accepted descriptor through _accept() so it is not wrapped back into
MocketSocket, and authenticate the peer the same way CPython's fallback does
since the CVE-2024-3219 fix. socket.socket stays patched, so mocking is
unchanged for everything except the loopback pair the event loop makes.

Refs kiwicom/pytest-recording#212, kiwicom/pytest-recording#213.
tests/test_http_gevent.py patches socket at import time, so the hijack has to be installed on mocket.socket.true_socket.

Signed-off-by: Simin Yuan <281164480+simin-yuan@users.noreply.github.com>
_loopback_socketpair() connects with setblocking(False) -- the same trick
CPython's own fallback uses -- and counts on the accept() that follows to
wait for the handshake, because only then is getpeername() meaningful.
The hijacked _accept() here returned a foreign peer without waiting, so on
Linux csock was still in SYN_SENT when the CVE check called getpeername()
and the test failed with ENOTCONN instead of the ConnectionError it is
about. Windows connects to the loopback synchronously and never showed it.

Drain the real connection inside the hijack, then close it.

Signed-off-by: Simin Yuan <281164480+simin-yuan@users.noreply.github.com>
@simin-yuan
simin-yuan force-pushed the fix/socketpair-without-c-socketpair branch from 58f8f4d to 373984a Compare November 2, 2026 19:03
@simin-yuan

Copy link
Copy Markdown
Owner Author

CI pre-check done: run 41505783453, 9/9 jobs success on Linux (incl. build (3.13) that was failing upstream). Closing the temporary PR.

@simin-yuan simin-yuan closed this Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant