Skip to content

Commit 4cdee86

Browse files
committed
bpo-30945: Fix create_server to handle the case when iface isn't IPv6 enabled
Patch by Antoine Pitrou.
1 parent 4fadf0c commit 4cdee86

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-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 heapq
2021
import itertools
2122
import logging
@@ -1349,9 +1350,22 @@ async def create_server(
13491350
try:
13501351
sock.bind(sa)
13511352
except OSError as err:
1352-
raise OSError(err.errno, 'error while attempting '
1353-
'to bind on address %r: %s'
1354-
% (sa, err.strerror.lower())) from None
1353+
msg = f'error while attempting to bind on address' \
1354+
f'{sa!r}: {err.strerror.lower()}'
1355+
if err.errno == errno.EADDRNOTAVAIL:
1356+
# Assume the family is not enabled (bpo-30945)
1357+
sockets.pop()
1358+
sock.close()
1359+
logger.warning(msg)
1360+
continue
1361+
raise OSError(err.errno, msg) from err
1362+
1363+
if not sockets:
1364+
failed_addrs = [info[4] for info in infos]
1365+
raise OSError(
1366+
f'could not bind on any address out of '
1367+
f'{failed_addrs!r}')
1368+
13551369
completed = True
13561370
finally:
13571371
if not completed:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix create_server() to handle the case when interface is not IPv6 enabled

0 commit comments

Comments
 (0)