Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asyncio.AbstractEventLoop.sock_connect broken for AF_BLUETOOTH #72116

Closed
rjordens mannequin opened this issue Sep 1, 2016 · 10 comments
Closed

asyncio.AbstractEventLoop.sock_connect broken for AF_BLUETOOTH #72116

rjordens mannequin opened this issue Sep 1, 2016 · 10 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@rjordens
Copy link
Mannequin

rjordens mannequin commented Sep 1, 2016

BPO 27929
Nosy @asvetlov, @1st1, @Vgr255, @miss-islington, @vincentbernat
PRs
  • bpo-27929: resolve names only for AF_INET/AF_INET6 with asyncio #32131
  • [3.10] bpo-27929: resolve names only for AF_INET/AF_INET6 with asyncio (GH-32131) #32164
  • [3.9] bpo-27929: resolve names only for AF_INET/AF_INET6 with asyncio (GH-32131) #32165
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2022-03-28.22:35:22.237>
    created_at = <Date 2016-09-01.13:59:55.702>
    labels = ['3.11', 'type-bug', '3.9', '3.10', 'expert-asyncio']
    title = 'asyncio.AbstractEventLoop.sock_connect broken for AF_BLUETOOTH'
    updated_at = <Date 2022-03-28.22:35:22.234>
    user = 'https://bugs.python.org/rjordens'

    bugs.python.org fields:

    activity = <Date 2022-03-28.22:35:22.234>
    actor = 'asvetlov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-03-28.22:35:22.237>
    closer = 'asvetlov'
    components = ['asyncio']
    creation = <Date 2016-09-01.13:59:55.702>
    creator = 'rjordens'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 27929
    keywords = ['patch', '3.5regression']
    message_count = 10.0
    messages = ['274131', '274132', '274134', '274142', '274201', '276623', '276916', '416218', '416220', '416222']
    nosy_count = 6.0
    nosy_names = ['asvetlov', 'yselivanov', 'rjordens', 'abarry', 'miss-islington', 'bernat']
    pr_nums = ['32131', '32164', '32165']
    priority = 'high'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue27929'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @rjordens
    Copy link
    Mannequin Author

    rjordens mannequin commented Sep 1, 2016

    Since 3.5.2 sock_connect() tries to be smart and resolves addresses for you if they fail a socket.inet_pton() check. But inet_pton() only supports AF_INET(6) and does not work for other address families that socket otherwise supports just fine (e.g. AF_BLUETOOTH).

    Before 3.5.2, in order to happily use bluetooth sockets with asyncio, you could just do:

        sock = socket.socket(family=socket.AF_BLUETOOTH, type=socket.SOCK_STREAM,
                    proto=socket.BTPROTO_RFCOMM)
        sock.setblocking(False)
        addr = "00:12:34:56:78:99"
        yield from loop.sock_connect(sock, (addr, 1))

    This is a regression.

    @rjordens rjordens mannequin added the topic-argument-clinic label Sep 1, 2016
    @rjordens
    Copy link
    Mannequin Author

    rjordens mannequin commented Sep 1, 2016

    The error for inet_pton() is:

    >>> import socket
    >>> socket.inet_pton(socket.AF_BLUETOOTH, "00:12:34:56:78:99")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    socket.error: [Errno 97] Address family not supported by protocol

    And the traceback in asyncio is:

    DEBUG:asyncio:Using selector: EpollSelector
    Traceback (most recent call last):
      File "log.py", line 91, in <module>
        main()
      File "log.py", line 84, in main
        loop.run_until_complete(log(loop, sys.argv[1]))
      File "/usr/lib/python3.5/asyncio/base_events.py", line 387, in run_until_complete
        return future.result()
      File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
        raise self._exception
      File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step
        result = coro.throw(exc)
      File "log.py", line 22, in log
        yield from loop.sock_connect(sock, (addr, 1))
      File "/usr/lib/python3.5/asyncio/selector_events.py", line 397, in sock_connect
        yield from resolved
      File "/usr/lib/python3.5/asyncio/futures.py", line 361, in __iter__
        yield self  # This tells Task to wait for completion.
      File "/usr/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
        future.result()
      File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
        raise self._exception
      File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
        result = self.fn(*self.args, **self.kwargs)
      File "/usr/lib/python3.5/socket.py", line 732, in getaddrinfo
        for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    socket.gaierror: [Errno -5] No address associated with hostname

    @Vgr255
    Copy link
    Mannequin

    Vgr255 mannequin commented Sep 1, 2016

    Thanks for the report! I'm unable to reproduce, as socket.AF_BLUETOOTH doesn't exist on my system, but surely someone else can.

    @Vgr255 Vgr255 mannequin changed the title asyncio.AbstractEventLoop.sock_connect brooken for AF_BLUETOOTH asyncio.AbstractEventLoop.sock_connect broken for AF_BLUETOOTH Sep 1, 2016
    @Vgr255 Vgr255 mannequin added the type-bug An unexpected behavior, bug, or error label Sep 1, 2016
    @gvanrossum
    Copy link
    Member

    Looks related (possibly a duplicate) of issue bpo-27136. Also related is a fix for the latter in python/asyncio#357. That fix is already in the CPython repo, but I guess it didn't make it into 3.5.2.

    @rjordens
    Copy link
    Mannequin Author

    rjordens mannequin commented Sep 2, 2016

    https://github.com/python/cpython/blob/master/Lib/asyncio/selector_events.py#L394
    https://github.com/python/asyncio/blob/master/asyncio/selector_events.py#L394

    AF_UNIX is special-cased.
    Maybe AF_BLUETOOTH and others should use that same special treatment.
    Or maybe only AF_INET, AF_INET6 should attempt resolving.

    @1st1
    Copy link
    Member

    1st1 commented Sep 15, 2016

    I'm not sure this is still relevant for the latest asyncio in 3.6. Robert, could you please test if this is still the case?

    @rjordens
    Copy link
    Mannequin Author

    rjordens mannequin commented Sep 18, 2016

    It is still in cpython master e6e9ddd.

    import asyncio
    import socket
    sock = socket.socket(family=socket.AF_BLUETOOTH,
                         type=socket.SOCK_STREAM,
                         proto=socket.BTPROTO_RFCOMM)
    sock.setblocking(False)
    addr = "00:12:34:56:78:99"
    loop = asyncio.get_event_loop()
    loop.run_until_complete(loop.sock_connect(sock, (addr, 1)))
    Traceback (most recent call last):
      File "/home/rj/work/hxm/t.py", line 9, in <module>
        loop.run_until_complete(loop.sock_connect(sock, (addr, 1)))
      File "/home/rj/src/cpython/Lib/asyncio/base_events.py", line 457, in run_until_complete
        return future.result()
      File "/home/rj/src/cpython/Lib/asyncio/futures.py", line 292, in result
        raise self._exception
      File "/home/rj/src/cpython/Lib/asyncio/tasks.py", line 241, in _step
        result = coro.throw(exc)
      File "/home/rj/src/cpython/Lib/asyncio/selector_events.py", line 416, in sock_connect
        yield from resolved
      File "/home/rj/src/cpython/Lib/asyncio/futures.py", line 379, in __iter__
        yield self  # This tells Task to wait for completion.
      File "/home/rj/src/cpython/Lib/asyncio/tasks.py", line 297, in _wakeup
        future.result()
      File "/home/rj/src/cpython/Lib/asyncio/futures.py", line 292, in result
        raise self._exception
      File "/home/rj/src/cpython/Lib/concurrent/futures/thread.py", line 55, in run
        result = self.fn(*self.args, **self.kwargs)
      File "/home/rj/src/cpython/Lib/socket.py", line 743, in getaddrinfo
        for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    socket.gaierror: [Errno -6] ai_family not supported

    @paulniklasweiss paulniklasweiss mannequin added 3.7 (EOL) end of life 3.8 only security fixes labels Mar 14, 2021
    @ned-deily ned-deily added 3.11 only security fixes and removed 3.7 (EOL) end of life 3.8 only security fixes labels Mar 26, 2022
    @asvetlov
    Copy link
    Contributor

    New changeset 5c30388 by Vincent Bernat in branch 'main':
    bpo-27929: resolve names only for AF_INET/AF_INET6 with asyncio (GH-32131)
    5c30388

    @miss-islington
    Copy link
    Contributor

    New changeset 2bcbc31 by Miss Islington (bot) in branch '3.10':
    bpo-27929: resolve names only for AF_INET/AF_INET6 with asyncio (GH-32131)
    2bcbc31

    @miss-islington
    Copy link
    Contributor

    New changeset f84fb55 by Miss Islington (bot) in branch '3.9':
    bpo-27929: resolve names only for AF_INET/AF_INET6 with asyncio (GH-32131)
    f84fb55

    @asvetlov asvetlov added 3.9 only security fixes 3.10 only security fixes labels Mar 28, 2022
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes topic-asyncio type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants