summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/base_events.py
diff options
context:
space:
mode:
authorQuentin Dawans <github@ovv.wtf>2019-04-09 13:40:59 (GMT)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-04-09 13:40:59 (GMT)
commit56065d4c8ac03042cb7e29ffda9b1ac544a37b4d (patch)
tree445bd69f3856da7a222a5065dea161c4689b0354 /Lib/asyncio/base_events.py
parent5aaac94eeb44697e92b0951385cd557bc27e0f6a (diff)
downloadcpython-56065d4c8ac03042cb7e29ffda9b1ac544a37b4d.zip
cpython-56065d4c8ac03042cb7e29ffda9b1ac544a37b4d.tar.gz
cpython-56065d4c8ac03042cb7e29ffda9b1ac544a37b4d.tar.bz2
bpo-34139: Remove unix datagram socket from FS before binding (GH-8323)
https://bugs.python.org/issue34139
Diffstat (limited to 'Lib/asyncio/base_events.py')
-rw-r--r--Lib/asyncio/base_events.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 36fe7e0..9b4b846 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -20,6 +20,7 @@ import heapq
import itertools
import os
import socket
+import stat
import subprocess
import threading
import time
@@ -1183,6 +1184,19 @@ class BaseEventLoop(events.AbstractEventLoop):
for addr in (local_addr, remote_addr):
if addr is not None and not isinstance(addr, str):
raise TypeError('string is expected')
+
+ if local_addr and local_addr[0] not in (0, '\x00'):
+ try:
+ if stat.S_ISSOCK(os.stat(local_addr).st_mode):
+ os.remove(local_addr)
+ 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',
+ local_addr, err)
+
addr_pairs_info = (((family, proto),
(local_addr, remote_addr)), )
else: