diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index 61938e90c375df..60664801184648 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -16,6 +16,7 @@ import collections import collections.abc import concurrent.futures +import errno import heapq import itertools import logging @@ -1349,9 +1350,22 @@ async def create_server( 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 = f'error while attempting to bind on address' \ + f'{sa!r}: {err.strerror.lower()}' + if err.errno == errno.EADDRNOTAVAIL: + # Assume the family is not enabled (bpo-30945) + sockets.pop() + sock.close() + logger.warning(msg) + continue + raise OSError(err.errno, msg) from err + + if not sockets: + failed_addrs = [info[4] for info in infos] + raise OSError( + f'could not bind on any address out of ' + f'{failed_addrs!r}') + completed = True finally: if not completed: diff --git a/Misc/NEWS.d/next/Library/2018-05-29-11-38-34.bpo-30945.zYP6IH.rst b/Misc/NEWS.d/next/Library/2018-05-29-11-38-34.bpo-30945.zYP6IH.rst new file mode 100644 index 00000000000000..ff94c6710dcf97 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-05-29-11-38-34.bpo-30945.zYP6IH.rst @@ -0,0 +1 @@ +Fix create_server() to handle the case when interface is not IPv6 enabled