Skip to content

Commit

Permalink
Guard against possible UNIX domain socket cleanup in Python 3.13
Browse files Browse the repository at this point in the history
This commit adds guards around code which cleans up UNIX domain
sockets, to protect against a change proposed at
python/cpython#111246
which would cause the socket to clean itself up on close.
  • Loading branch information
ronf committed Dec 23, 2023
1 parent 2f1f5da commit 5816813
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
5 changes: 4 additions & 1 deletion tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ async def stop(self):
self._server.close()
await self._server.wait_closed()

os.remove(self._path)
try:
os.remove(self._path)
except OSError:
pass


class _TestAgent(AsyncTestCase):
Expand Down
50 changes: 39 additions & 11 deletions tests/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,10 @@ async def test_forward_local_path_to_port(self):
async with conn.forward_local_path_to_port('local', '', 7):
await self._check_local_unix_connection('local')

os.remove('local')
try:
os.remove('local')
except OSError:
pass

@unittest.skipIf(sys.platform == 'win32',
'skip UNIX domain socket tests on Windows')
Expand All @@ -665,7 +668,10 @@ async def test_forward_local_path_to_port_failure(self):
with self.assertRaises(OSError):
await conn.forward_local_path_to_port('local', '', 7)

os.remove('local')
try:
os.remove('local')
except OSError:
pass

@asynctest
async def test_forward_local_port_pause(self):
Expand Down Expand Up @@ -798,7 +804,11 @@ async def test_forward_remote_port_to_path(self):

server.close()
await server.wait_closed()
os.remove('local')

try:
os.remove('local')
except OSError:
pass

@asynctest
async def test_forward_remote_specific_port(self):
Expand Down Expand Up @@ -1020,7 +1030,10 @@ async def test_unix_server(self):
await listener.wait_closed()
listener.close()

os.remove('echo')
try:
os.remove('echo')
except OSError:
pass

@asynctest
async def test_unix_server_open(self):
Expand Down Expand Up @@ -1053,7 +1066,10 @@ async def test_unix_server_non_async(self):
async with conn.start_unix_server(_unix_listener_non_async, path):
await self._check_local_unix_connection('echo')

os.remove('echo')
try:
os.remove('echo')
except OSError:
pass

@asynctest
async def test_unix_server_failure(self):
Expand All @@ -1071,7 +1087,10 @@ async def test_forward_local_path(self):
async with conn.forward_local_path('local', '/echo'):
await self._check_local_unix_connection('local')

os.remove('local')
try:
os.remove('local')
except OSError:
pass

@asynctest
async def test_forward_local_port_to_path_accept_handler(self):
Expand Down Expand Up @@ -1149,8 +1168,11 @@ async def test_forward_remote_path(self):
server.close()
await server.wait_closed()

os.remove('echo')
os.remove('local')
try:
os.remove('echo')
os.remove('local')
except OSError:
pass

@asynctest
async def test_forward_remote_path_to_port(self):
Expand All @@ -1167,11 +1189,14 @@ async def test_forward_remote_path_to_port(self):
path, '127.0.0.1', server_port):
await self._check_local_unix_connection('echo')

os.remove('echo')

server.close()
await server.wait_closed()

try:
os.remove('echo')
except OSError:
pass

@asynctest
async def test_forward_remote_path_failure(self):
"""Test failure of forwarding a remote UNIX domain path"""
Expand All @@ -1184,7 +1209,10 @@ async def test_forward_remote_path_failure(self):
with self.assertRaises(asyncssh.ChannelListenError):
await conn.forward_remote_path(path, 'local')

os.remove('echo')
try:
os.remove('echo')
except OSError:
pass

@asynctest
async def test_forward_remote_path_not_permitted(self):
Expand Down

0 comments on commit 5816813

Please sign in to comment.