cpython: a3b162d5e70a (original) (raw)
Mercurial > cpython
changeset 104414:a3b162d5e70a 3.5
Issue #28399: Remove UNIX socket from FS before binding. Patch by Коренберг Марк. [#28399]
Yury Selivanov yury@magic.io | |
---|---|
date | Sun, 09 Oct 2016 12:15:08 -0400 |
parents | 94c9c314f5d9 |
children | 019c5c2f1239 8d877876aa89 |
files | Lib/asyncio/unix_events.py Lib/test/test_asyncio/test_unix_events.py Misc/NEWS |
diffstat | 3 files changed, 21 insertions(+), 5 deletions(-)[+] [-] Lib/asyncio/unix_events.py 11 Lib/test/test_asyncio/test_unix_events.py 12 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -258,6 +258,17 @@ class _UnixSelectorEventLoop(selector_ev sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
# Check for abstract socket. `str` and `bytes` paths are supported.[](#l1.7)
if path[0] not in (0, '\x00'):[](#l1.8)
try:[](#l1.9)
if stat.S_ISSOCK(os.stat(path).st_mode):[](#l1.10)
os.remove(path)[](#l1.11)
except FileNotFoundError:[](#l1.12)
pass[](#l1.13)
except OSError as err:[](#l1.14)
# Directory may have permissions only to create socket.[](#l1.15)
logger.error('Unable to check or remove stale UNIX socket %r: %r', path, err)[](#l1.16)
+ try: sock.bind(path) except OSError as exc:
--- a/Lib/test/test_asyncio/test_unix_events.py +++ b/Lib/test/test_asyncio/test_unix_events.py @@ -241,11 +241,13 @@ class SelectorEventLoopUnixSocketTests(t with test_utils.unix_socket_path() as path: sock = socket.socket(socket.AF_UNIX) sock.bind(path)
with sock:[](#l2.7)
coro = self.loop.create_unix_server(lambda: None, path)[](#l2.8)
with self.assertRaisesRegex(OSError,[](#l2.9)
'Address.*is already in use'):[](#l2.10)
self.loop.run_until_complete(coro)[](#l2.11)
sock.listen(1)[](#l2.12)
sock.close()[](#l2.13)
coro = self.loop.create_unix_server(lambda: None, path)[](#l2.15)
srv = self.loop.run_until_complete(coro)[](#l2.16)
srv.close()[](#l2.17)
self.loop.run_until_complete(srv.wait_closed())[](#l2.18)
def test_create_unix_server_existing_path_nonsock(self): with tempfile.NamedTemporaryFile() as file: