-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-111246: Remove listening Unix socket on close #111483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
21ff6be
21e9d8c
df3b74e
93571fe
acadacb
1db87b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import asyncio | ||
import os | ||
import socket | ||
import time | ||
import threading | ||
import unittest | ||
|
@@ -147,6 +149,74 @@ async def serve(*args): | |
await task2 | ||
|
||
|
||
class UnixServerCleanupTests(unittest.IsolatedAsyncioTestCase): | ||
@socket_helper.skip_unless_bind_unix_socket | ||
async def test_unix_server_addr_cleanup(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind adding one-line comments to the new tests explaining what each test checks? They look so similar I first thought you had accidentally copied the test a few times. :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. A commit with comments have been pushed. |
||
with test_utils.unix_socket_path() as addr: | ||
async def serve(*args): | ||
pass | ||
|
||
srv = await asyncio.start_unix_server(serve, addr) | ||
|
||
srv.close() | ||
self.assertFalse(os.path.exists(addr)) | ||
|
||
@socket_helper.skip_unless_bind_unix_socket | ||
async def test_unix_server_sock_cleanup(self): | ||
with test_utils.unix_socket_path() as addr: | ||
async def serve(*args): | ||
pass | ||
|
||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
sock.bind(addr) | ||
|
||
srv = await asyncio.start_unix_server(serve, sock=sock) | ||
|
||
srv.close() | ||
self.assertFalse(os.path.exists(addr)) | ||
|
||
@socket_helper.skip_unless_bind_unix_socket | ||
async def test_unix_server_cleanup_gone(self): | ||
with test_utils.unix_socket_path() as addr: | ||
async def serve(*args): | ||
pass | ||
|
||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
sock.bind(addr) | ||
|
||
srv = await asyncio.start_unix_server(serve, sock=sock) | ||
|
||
os.unlink(addr) | ||
|
||
srv.close() | ||
|
||
@socket_helper.skip_unless_bind_unix_socket | ||
async def test_unix_server_cleanup_replaced(self): | ||
with test_utils.unix_socket_path() as addr: | ||
async def serve(*args): | ||
pass | ||
|
||
srv = await asyncio.start_unix_server(serve, addr) | ||
|
||
os.unlink(addr) | ||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
sock.bind(addr) | ||
|
||
srv.close() | ||
self.assertTrue(os.path.exists(addr)) | ||
|
||
@socket_helper.skip_unless_bind_unix_socket | ||
async def test_unix_server_cleanup_prevented(self): | ||
with test_utils.unix_socket_path() as addr: | ||
async def serve(*args): | ||
pass | ||
|
||
srv = await asyncio.start_unix_server(serve, addr, cleanup_socket=False) | ||
|
||
srv.close() | ||
self.assertTrue(os.path.exists(addr)) | ||
|
||
|
||
@unittest.skipUnless(hasattr(asyncio, 'ProactorEventLoop'), 'Windows only') | ||
class ProactorStartServerTests(BaseStartServer, unittest.TestCase): | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
:meth:`asyncio.loop.create_unix_server` will now automatically remove the | ||
Unix socket when the server is closed. |
Uh oh!
There was an error while loading. Please reload this page.