summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-01-22 17:15:08 (GMT)
committerGitHub <noreply@github.com>2024-01-22 17:15:08 (GMT)
commit4bbb9f6f29e08d88ebc4965165b8aa1aec47f427 (patch)
tree2eb7aaabb525dcdcd71917befb7f42b1a4143ad9 /Lib
parent4890ac136b48eebb4d84fde55988b82d0220cfd0 (diff)
downloadcpython-4bbb9f6f29e08d88ebc4965165b8aa1aec47f427.zip
cpython-4bbb9f6f29e08d88ebc4965165b8aa1aec47f427.tar.gz
cpython-4bbb9f6f29e08d88ebc4965165b8aa1aec47f427.tar.bz2
[3.12] gh-75128: Ignore EADDRNOTAVAIL error in asyncio.BaseEventLoop.create_server() (GH-114420) (GH-114441)
(cherry picked from commit a53e56e7d88b4f2a2943c9f191024198009fcf9e) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Antoine Pitrou <pitrou@free.fr>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/asyncio/base_events.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 5318a59..06024cb 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -16,6 +16,7 @@ to modify the meaning of the API call itself.
import collections
import collections.abc
import concurrent.futures
+import errno
import functools
import heapq
import itertools
@@ -1556,9 +1557,22 @@ class BaseEventLoop(events.AbstractEventLoop):
try:
sock.bind(sa)
except OSError as err:
- raise OSError(err.errno, 'error while attempting '
- 'to bind on address %r: %s'
- % (sa, err.strerror.lower())) from None
+ msg = ('error while attempting '
+ 'to bind on address %r: %s'
+ % (sa, err.strerror.lower()))
+ if err.errno == errno.EADDRNOTAVAIL:
+ # Assume the family is not enabled (bpo-30945)
+ sockets.pop()
+ sock.close()
+ if self._debug:
+ logger.warning(msg)
+ continue
+ raise OSError(err.errno, msg) from None
+
+ if not sockets:
+ raise OSError('could not bind on any address out of %r'
+ % ([info[4] for info in infos],))
+
completed = True
finally:
if not completed: