import collections
import collections.abc
import concurrent.futures
+import errno
import functools
import heapq
import itertools
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: