Skip to content

Commit a53e56e

Browse files
gh-75128: Ignore EADDRNOTAVAIL error in asyncio.BaseEventLoop.create_server() (GH-114420)
Co-authored-by: Antoine Pitrou <[email protected]>
1 parent 8ccd1ba commit a53e56e

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Lib/asyncio/base_events.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import collections
1717
import collections.abc
1818
import concurrent.futures
19+
import errno
1920
import functools
2021
import heapq
2122
import itertools
@@ -1585,9 +1586,22 @@ async def create_server(
15851586
try:
15861587
sock.bind(sa)
15871588
except OSError as err:
1588-
raise OSError(err.errno, 'error while attempting '
1589-
'to bind on address %r: %s'
1590-
% (sa, err.strerror.lower())) from None
1589+
msg = ('error while attempting '
1590+
'to bind on address %r: %s'
1591+
% (sa, err.strerror.lower()))
1592+
if err.errno == errno.EADDRNOTAVAIL:
1593+
# Assume the family is not enabled (bpo-30945)
1594+
sockets.pop()
1595+
sock.close()
1596+
if self._debug:
1597+
logger.warning(msg)
1598+
continue
1599+
raise OSError(err.errno, msg) from None
1600+
1601+
if not sockets:
1602+
raise OSError('could not bind on any address out of %r'
1603+
% ([info[4] for info in infos],))
1604+
15911605
completed = True
15921606
finally:
15931607
if not completed:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Ignore an :exc:`OSError` in :meth:`asyncio.BaseEventLoop.create_server` when
2+
IPv6 is available but the interface cannot actually support it.

0 commit comments

Comments
 (0)