diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index e4b3d848923f8c9..0814f75ab1aab35 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -608,8 +608,23 @@ def setUp(self): else: raise self.serv.listen() - self.serverExplicitReady() self.serv.settimeout(support.LOOPBACK_TIMEOUT) + # gh-158883: The local CID can be known even if no transport is able + # to deliver a connection to it. Check that before the client thread + # is released: once it is, a failing connect() leaves accept() below + # waiting for the timeout. + with socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM) as probe: + probe.settimeout(support.LOOPBACK_TIMEOUT) + try: + probe.connect((cid, VSOCKPORT)) + except OSError as exc: + if exc.errno == errno.ENODEV: + self.skipTest(f"connect() failed with {exc!r}") + else: + raise + conn, _ = self.serv.accept() + conn.close() + self.serverExplicitReady() self.conn, self.connaddr = self.serv.accept() self.addCleanup(self.conn.close) diff --git a/Misc/NEWS.d/next/Tests/2026-10-13-18-48-29.gh-issue-158883.vS0cKd.rst b/Misc/NEWS.d/next/Tests/2026-10-13-18-48-29.gh-issue-158883.vS0cKd.rst new file mode 100644 index 000000000000000..82ec67b55e64db2 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2026-10-13-18-48-29.gh-issue-158883.vS0cKd.rst @@ -0,0 +1,3 @@ +Skip ``test_socket.ThreadedVSOCKSocketStreamTest`` when connecting to the +local ``AF_VSOCK`` address fails with :data:`~errno.ENODEV`, instead of +failing with a timeout.