Skip to content

Commit 45db419

Browse files
authored
[3.11] gh-119461: Fix ThreadedVSOCKSocketStreamTest (#129171)
Fix ThreadedVSOCKSocketStreamTest: if get_cid() returns the host address or the "any" address, use the local communication address (loopback): VMADDR_CID_LOCAL. On Linux 6.9, apparently, the /dev/vsock device is now available but get_cid() returns VMADDR_CID_ANY (-1). (cherry picked from commit e94dbe4) (cherry picked from commit c750061) (cherry picked from commit cbfe302)
1 parent 49edb99 commit 45db419

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Lib/test/test_socket.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
# test unicode string and carriage return
4444
MSG = 'Michael Gilfix was here\u1234\r\n'.encode('utf-8')
4545

46+
VMADDR_CID_LOCAL = 1
4647
VSOCKPORT = 1234
4748
AIX = platform.system() == "AIX"
4849
WSL = "microsoft-standard-WSL" in platform.release()
@@ -127,8 +128,8 @@ def _have_socket_qipcrtr():
127128

128129
def _have_socket_vsock():
129130
"""Check whether AF_VSOCK sockets are supported on this host."""
130-
ret = get_cid() is not None
131-
return ret
131+
cid = get_cid()
132+
return (cid is not None)
132133

133134

134135
def _have_socket_bluetooth():
@@ -471,8 +472,6 @@ def clientTearDown(self):
471472
@unittest.skipIf(WSL, 'VSOCK does not work on Microsoft WSL')
472473
@unittest.skipUnless(HAVE_SOCKET_VSOCK,
473474
'VSOCK sockets required for this test.')
474-
@unittest.skipUnless(get_cid() != 2,
475-
"This test can only be run on a virtual guest.")
476475
class ThreadedVSOCKSocketStreamTest(unittest.TestCase, ThreadableTest):
477476

478477
def __init__(self, methodName='runTest'):
@@ -494,10 +493,16 @@ def clientSetUp(self):
494493
self.cli = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)
495494
self.addCleanup(self.cli.close)
496495
cid = get_cid()
496+
if cid in (socket.VMADDR_CID_HOST, socket.VMADDR_CID_ANY):
497+
# gh-119461: Use the local communication address (loopback)
498+
cid = VMADDR_CID_LOCAL
497499
self.cli.connect((cid, VSOCKPORT))
498500

499501
def testStream(self):
500-
msg = self.conn.recv(1024)
502+
try:
503+
msg = self.conn.recv(1024)
504+
except PermissionError as exc:
505+
self.skipTest(repr(exc))
501506
self.assertEqual(msg, MSG)
502507

503508
def _testStream(self):

0 commit comments

Comments
 (0)