summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-10-09 16:16:08 (GMT)
committerYury Selivanov <yury@magic.io>2016-10-09 16:16:08 (GMT)
commit88e8aca78d71fa917a057e8d60b24f4a364d3248 (patch)
tree81981ba1a9fbf053b811a83e9cc0fddf47c867e4 /Lib
parent75907bc5b500fa6708c06c88261e5c6fa189f20e (diff)
parent908d55dd7e395779ed1eb5c96664aca6297fedaa (diff)
downloadcpython-88e8aca78d71fa917a057e8d60b24f4a364d3248.zip
cpython-88e8aca78d71fa917a057e8d60b24f4a364d3248.tar.gz
cpython-88e8aca78d71fa917a057e8d60b24f4a364d3248.tar.bz2
Merge 3.5 (issue #28399)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/asyncio/unix_events.py11
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py12
2 files changed, 18 insertions, 5 deletions
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index 8524ba9..2843678 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:
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index 0d54e3a..ce897ed 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -241,11 +241,13 @@ class SelectorEventLoopUnixSocketTests(test_utils.TestCase):
with test_utils.unix_socket_path() as path:
sock = socket.socket(socket.AF_UNIX)
sock.bind(path)
- with sock:
- coro = self.loop.create_unix_server(lambda: None, path)
- with self.assertRaisesRegex(OSError,
- 'Address.*is already in use'):
- self.loop.run_until_complete(coro)
+ sock.listen(1)
+ sock.close()
+
+ coro = self.loop.create_unix_server(lambda: None, path)
+ srv = self.loop.run_until_complete(coro)
+ srv.close()
+ self.loop.run_until_complete(srv.wait_closed())
def test_create_unix_server_existing_path_nonsock(self):
with tempfile.NamedTemporaryFile() as file: