From 908d55dd7e395779ed1eb5c96664aca6297fedaa Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Sun, 9 Oct 2016 12:15:08 -0400 Subject: Issue #28399: Remove UNIX socket from FS before binding. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch by Коренберг Марк. --- Lib/asyncio/unix_events.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'Lib/asyncio/unix_events.py') diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 42a8b85981f..65b61db66ac 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -258,6 +258,17 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop): sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + # Check for abstract socket. `str` and `bytes` paths are supported. + if path[0] not in (0, '\x00'): + try: + if stat.S_ISSOCK(os.stat(path).st_mode): + os.remove(path) + except FileNotFoundError: + pass + except OSError as err: + # Directory may have permissions only to create socket. + logger.error('Unable to check or remove stale UNIX socket %r: %r', path, err) + try: sock.bind(path) except OSError as exc: -- cgit v1.2.3