gh-75128: Ignore EADDRNOTAVAIL error in asyncio.BaseEventLoop.create_server() (GH-114420)

Co-authored-by: Antoine Pitrou <pitrou@free.fr>
This commit is contained in:
Serhiy Storchaka 2024-01-22 18:40:35 +02:00 committed by GitHub
parent 8ccd1ba461
commit a53e56e7d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View File

@ -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
@ -1585,9 +1586,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:

View File

@ -0,0 +1,2 @@
Ignore an :exc:`OSError` in :meth:`asyncio.BaseEventLoop.create_server` when
IPv6 is available but the interface cannot actually support it.