Repository navigation
docs: explain the Windows asyncio socketpair requirement - #569
Open
simin-yuan wants to merge 3 commits into
Open
simin-yuan wants to merge 3 commits into
simin-yuan wants to merge 3 commits into
Conversation
--disable-socket also blocks the loopback pair that asyncio builds for its self-pipe on Windows, so every async test fails during setup with SocketBlockedError. Record the working configuration, note that --allow-unix-socket does not apply, and show that outbound connections stay blocked. See kiwicom/pytest-recording#212 and kiwicom/pytest-recording#213 for the same failure in another network-blocking plugin. Signed-off-by: Simin Yuan <281164480+simin-yuan@users.noreply.github.com>
Author
|
For reference, pytest-recording took the same approach and shipped it in 0.14.1 (kiwicom/pytest-recording#213). |
--allow-hosts skips disable_socket() entirely (pytest_runtest_setup, __init__.py:220), so socket() and the DNS helpers stay unpatched and only connect() keeps the allow-list check. Found by @mgkvibez in miketheman#568. Signed-off-by: Simin Yuan <281164480+simin-yuan@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #568
Summary
On Windows,
--disable-socketalso blocks theAF_INETloopback pair thatasynciobuilds for its self-pipe, so every async test fails during setup withSocketBlockedError. This adds an FAQ entry to the README that names thefailure, shows the configuration that works, and states that outbound
connections stay blocked.
Why
_sockethas nosocketpair()on Windows, sosocket.socketpair()takes thepure-Python path: it binds an
AF_INETlistener on127.0.0.1, connects asecond socket to it, and returns the pair. The guard blocks that connection,
so
asyncio.new_event_loop()raises before the test runs.Measured
Windows 11, CPython 3.11.16, 3.12.14 and 3.13.13, pytest 9.2.0,
pytest-socket 0.8.1, three-test probe (create a loop,
socket.socketpair()round trip, one@pytest.mark.asynciotest):--disable-socket--disable-socket --allow-hosts=127.0.0.1--disable-socket --allow-hosts=127.0.0.1,::1--disable-socket --allow-unix-socket--disable-socket --allow-unix-socket --allow-hosts=127.0.0.1,::1With
--disable-socket --allow-hosts=127.0.0.1,::1,socket.create_connection(("192.0.2.1", 80))still raisespytest_socket.SocketConnectBlockedError; the same call fails when no blockeris active, so the check is a real one and not an artefact of the address.
Scope
Documentation only, no code change, no test change. A narrower alternative,
exempting just the pair created inside
socketpair()so loopback stays blockedfor user code, is proposed in kiwicom/pytest-recording#213 (still open) and can
be done separately if you prefer that to the documented workaround.
Related: kiwicom/pytest-recording#212, kiwicom/pytest-recording#213.