]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-75128: Ignore EADDRNOTAVAIL error in asyncio.BaseEventLoop.create_server() (GH...
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 22 Jan 2024 16:40:35 +0000 (18:40 +0200)
committerGitHub <noreply@github.com>
Mon, 22 Jan 2024 16:40:35 +0000 (18:40 +0200)
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
Lib/asyncio/base_events.py
Misc/NEWS.d/next/Library/2024-01-22-12-10-34.gh-issue-75128.4FGlRS.rst [new file with mode: 0644]

index a8870b636d1df50fd0fdeee0c1d09b68cad84e86..c60d7688ef8c7723b46955d0936aeeb1e8c08d1d 100644 (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:
diff --git a/Misc/NEWS.d/next/Library/2024-01-22-12-10-34.gh-issue-75128.4FGlRS.rst b/Misc/NEWS.d/next/Library/2024-01-22-12-10-34.gh-issue-75128.4FGlRS.rst
new file mode 100644 (file)
index 0000000..d875148
--- /dev/null
@@ -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.