[Python-checkins] cpython (merge 3.5 -> 3.6): Merge 3.5 (issue #28399)

yury.selivanov python-checkins at python.org
Sun Oct 9 12:16:35 EDT 2016


https://hg.python.org/cpython/rev/019c5c2f1239
changeset: 104415:019c5c2f1239
branch: 3.6
parent: 104412:60c5c77c0190
parent: 104414:a3b162d5e70a
user: Yury Selivanov <yury at magic.io>
date: Sun Oct 09 12:16:08 2016 -0400
summary:
 Merge 3.5 (issue #28399)
files:
 Lib/asyncio/unix_events.py | 11 ++++++++++
 Lib/test/test_asyncio/test_unix_events.py | 12 ++++++----
 Misc/NEWS | 3 ++
 3 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -258,6 +258,17 @@
 
 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
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -241,11 +241,13 @@
 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:
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -216,6 +216,9 @@
 
 - Issue #28372: Fix asyncio to support formatting of non-python coroutines.
 
+- Issue #28399: Remove UNIX socket from FS before binding.
+ Patch by Коренберг Марк.
+
 Windows
 -------
 
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /