Title: `create_connection` and `create_server` in `asyncio` didn't work with a Python build with IPv6 disabled · Issue #121913 · python/cpython · GitHub
Open Graph Title: `create_connection` and `create_server` in `asyncio` didn't work with a Python build with IPv6 disabled · Issue #121913 · python/cpython
X Title: `create_connection` and `create_server` in `asyncio` didn't work with a Python build with IPv6 disabled · Issue #121913 · python/cpython
Description: Bug report Bug description: Build Python with the configuration --disable-ipv6, and run the test with ./python.exe -m test test_asyncio.test_events -m 'test_create_connection_local_addr_skip_different_family' -v. You will encounter the f...
Open Graph Description: Bug report Bug description: Build Python with the configuration --disable-ipv6, and run the test with ./python.exe -m test test_asyncio.test_events -m 'test_create_connection_local_addr_skip_differ...
X Description: Bug report Bug description: Build Python with the configuration --disable-ipv6, and run the test with ./python.exe -m test test_asyncio.test_events -m 'test_create_connection_local_addr_skip_di...
Opengraph URL: https://github.com/python/cpython/issues/121913
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`create_connection` and `create_server` in `asyncio` didn't work with a Python build with IPv6 disabled","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nBuild Python with the configuration `--disable-ipv6`, and run the test with `./python.exe -m test test_asyncio.test_events -m 'test_create_connection_local_addr_skip_different_family' -v`. You will encounter the following error stack:\r\n\r\n```\r\nERROR: test_create_connection_local_addr_skip_different_family (test.test_asyncio.test_events.SelectEventLoopTests.test_create_connection_local_addr_skip_different_family)\r\n----------------------------------------------------------------------\r\nTraceback (most recent call last):\r\n File \"/Users/asaka/Codes/cpython/Lib/asyncio/base_events.py\", line 1026, in _connect_sock\r\n sock.bind(laddr)\r\nOSError: bind(): bad family\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n File \"/Users/asaka/Codes/cpython/Lib/test/test_asyncio/test_events.py\", line 695, in test_create_connection_local_addr_skip_different_family\r\n self.loop.run_until_complete(f)\r\n File \"/Users/asaka/Codes/cpython/Lib/asyncio/base_events.py\", line 721, in run_until_complete\r\n return future.result()\r\n File \"/Users/asaka/Codes/cpython/Lib/asyncio/base_events.py\", line 1138, in create_connection\r\n sock = await self._connect_sock(exceptions, addrinfo, laddr_infos)\r\n File \"/Users/asaka/Codes/cpython/Lib/asyncio/base_events.py\", line 1032, in _connect_sock\r\n f'{exc.strerror.lower()}'\r\nAttributeError: 'NoneType' object has no attribute 'lower'\r\n```\r\n\r\nThis issue not only affects the test but also user's code.\r\n\r\nAfter some research, I found that it's caused by these two functions, which use `getaddrinfo` to get a list of connection infos and then attempt to call `bind` for each of the infos, ignoring `OSError` until a working one is found.\r\n\r\nHowever, in the iteration code, it attempts to use `OSError().strerror` to create a new error. Unfortunately, some `OSError` instances have a `strerror` field of `None`. The error raised by `sock.bind` with `AF_INET6` when `--disable-ipv6` is used does not have this field, leading to an error that prevents the iteration loop from trying the next potential solution.\r\n\r\nThere are already reports for the missing `strerror` / `errno` fields issues: [https://github.com/python/cpython/issues/109601](https://github.com/python/cpython/issues/109601) and [https://github.com/python/cpython/issues/50720](https://github.com/python/cpython/issues/50720) with a draft PR #109720.\r\n\r\nBut before we fix this issue, should we provide a workaround for this specific problem, like using `str(exc)` instead of `exc.strerror`, or skip this loop if `not socket.has_ipv6` and current family is `AF_INET6`?\r\n\r\n### CPython versions tested on:\r\n\r\nCPython main branch\r\n\r\n### Operating systems tested on:\r\n\r\nmacOS\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-122269\n* gh-122278\n* gh-122279\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/aisk","@type":"Person","name":"aisk"},"datePublished":"2024-07-17T13:37:35Z","url":"https://github.com/python/cpython/issues/121913"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c0b17e2e-6f5d-5754-d5e0-3196ecdb1624 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8694:106F5D:D494A4:11D61DD:6B005475 |
| html-safe-nonce | b6183d494c0a4443c6160c681df7b511f488a1209d5624538e47054c234dc48b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Njk0OjEwNkY1RDpENDk0QTQ6MTFENjFERDo2QjAwNTQ3NSIsInZpc2l0b3JfaWQiOiI3MzQyNjgzMTkwNjE3NzI0MDIxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e2f879b690c6cd1a78f62daa7dff13cdc3f38ef1d0b00c707ced5f62f11e4ca4 |
| hovercard-subject-tag | issue:2413651427 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/121913/issue_layout |
| twitter:image | https://opengraph.githubassets.com/01d2fca8a77b849898209d7800f80002f3035bd004ea66ffec3ce3d6fc68a3d1/python/cpython/issues/121913 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/01d2fca8a77b849898209d7800f80002f3035bd004ea66ffec3ce3d6fc68a3d1/python/cpython/issues/121913 |
| og:image:alt | Bug report Bug description: Build Python with the configuration --disable-ipv6, and run the test with ./python.exe -m test test_asyncio.test_events -m 'test_create_connection_local_addr_skip_differ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aisk |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width