GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `create_connection` and `create_server` in `asyncio` didn't work with a Python build with IPv6 disabled · Issue #121913 · python/cpython

create_connection and create_server in asyncio didn't work with a Python build with IPv6 disabled #121913

New issue
Copy link
New issue
Copy link
Closed
Closed
create_connection and create_server in asyncio didn't work with a Python build with IPv6 disabled#121913
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@aisk
aisk
opened on Jul 17, 2024
Issue body actions

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 following error stack:

ERROR: test_create_connection_local_addr_skip_different_family (test.test_asyncio.test_events.SelectEventLoopTests.test_create_connection_local_addr_skip_different_family)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/asaka/Codes/cpython/Lib/asyncio/base_events.py", line 1026, in _connect_sock
    sock.bind(laddr)
OSError: bind(): bad family

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/asaka/Codes/cpython/Lib/test/test_asyncio/test_events.py", line 695, in test_create_connection_local_addr_skip_different_family
    self.loop.run_until_complete(f)
  File "/Users/asaka/Codes/cpython/Lib/asyncio/base_events.py", line 721, in run_until_complete
    return future.result()
  File "/Users/asaka/Codes/cpython/Lib/asyncio/base_events.py", line 1138, in create_connection
    sock = await self._connect_sock(exceptions, addrinfo, laddr_infos)
  File "/Users/asaka/Codes/cpython/Lib/asyncio/base_events.py", line 1032, in _connect_sock
    f'{exc.strerror.lower()}'
AttributeError: 'NoneType' object has no attribute 'lower'

This issue not only affects the test but also user's code.

After 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.

However, 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.

There are already reports for the missing strerror / errno fields issues: #109601 and #50720 with a draft PR #109720.

But 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?

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

  • gh-121913: Using str(exc) instead of exc.strerror in asyncio.base_events #122269
  • [3.13] gh-121913: Use str(exc) instead of exc.strerror in asyncio.base_events (GH-122269) #122278
  • [3.12] gh-121913: Use str(exc) instead of exc.strerror in asyncio.base_events (GH-122269) #122279

Activity

  1. aisk
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    topic-asyncio
    on Jul 17, 2024
  2. github-project-automation
    added this to asyncioon Jul 17, 2024
  3. github-project-automation
    moved this to Todo in asyncioon Jul 17, 2024
  4. kumaraditya303 commented on Jul 25, 2024

    @kumaraditya303
    kumaraditya303
    on Jul 25, 2024
    Contributor
    More actions

    Using str(exc) makes sense to me, can you create a PR for it @aisk ?

  5. aisk commented on Jul 25, 2024

    @aisk
    aisk
    on Jul 25, 2024
    MemberAuthor
    More actions

    Sure, working on it.

  6. kumaraditya303
    added a commit that references this issue on Jul 25, 2024

    gh-121913: Use str(exc) instead of exc.strerror in `asyncio.base_even…

    070f1e2
  7. miss-islington
    added 2 commits that reference this issue on Jul 25, 2024

    pythongh-121913: Use str(exc) instead of exc.strerror in `asyncio.bas…

    658de64

    pythongh-121913: Use str(exc) instead of exc.strerror in `asyncio.bas…

    602d7ed
  8. kumaraditya303 commented on Jul 25, 2024

    @kumaraditya303
    kumaraditya303
    on Jul 25, 2024
    Contributor
    More actions

    Thanks

  9. kumaraditya303
    closed this as completedon Jul 25, 2024
  10. github-project-automation
    moved this from Todo to Done in asyncioon Jul 25, 2024
  11. kumaraditya303
    added 2 commits that reference this issue on Jul 25, 2024

    [3.12] gh-121913: Use str(exc) instead of exc.strerror in `asyncio.ba…

    0300e33

    [3.13] gh-121913: Use str(exc) instead of exc.strerror in `asyncio.ba…

    d1af4f5
  12. shadchin
    added a commit that references this issue on Aug 11, 2024

    Fix test_create_server_4

    da8c456
  13. fantix
    added a commit that references this issue on Aug 13, 2024

    Fix test_create_server_4 with Python 3.12.5 (#614)

    62f9239
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • asyncio
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.