This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: asyncio.AbstractEventLoop.sock_connect broken for AF_BLUETOOTH
Type: behavior Stage: resolved
Components: asyncio Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: abarry, asvetlov, bernat, miss-islington, rjordens, yselivanov
Priority: high Keywords: 3.5regression, patch

Created on 2016-09-01 13:59 by rjordens, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 32131 merged bernat, 2022-03-26 18:17
PR 32164 merged miss-islington, 2022-03-28 21:50
PR 32165 merged miss-islington, 2022-03-28 21:50
Messages (10)
msg274131 - (view) Author: Robert Jordens (rjordens) * Date: 2016-09-01 13:59
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.
msg274132 - (view) Author: Robert Jordens (rjordens) * Date: 2016-09-01 14:01
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
msg274134 - (view) Author: Anilyka Barry (abarry) * (Python triager) Date: 2016-09-01 14:15
Thanks for the report! I'm unable to reproduce, as `socket.AF_BLUETOOTH` doesn't exist on my system, but surely someone else can.
msg274142 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2016-09-01 15:32
Looks related (possibly a duplicate) of issue #27136. Also related is a fix for the latter in https://github.com/python/asyncio/pull/357. That fix is already in the CPython repo, but I guess it didn't make it into 3.5.2.
msg274201 - (view) Author: Robert Jordens (rjordens) * Date: 2016-09-02 04:30
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.
msg276623 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2016-09-15 21:37
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?
msg276916 - (view) Author: Robert Jordens (rjordens) * Date: 2016-09-18 21:22
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
msg416218 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-03-28 21:50
New changeset 5c30388f3c586ba2f33e349e22e5949cb92de621 by Vincent Bernat in branch 'main':
bpo-27929: resolve names only for AF_INET/AF_INET6 with asyncio (GH-32131)
https://github.com/python/cpython/commit/5c30388f3c586ba2f33e349e22e5949cb92de621
msg416220 - (view) Author: miss-islington (miss-islington) Date: 2022-03-28 22:15
New changeset 2bcbc3113dee6c35631595ec0d5ee3a8dd2a2ddd by Miss Islington (bot) in branch '3.10':
bpo-27929: resolve names only for AF_INET/AF_INET6 with asyncio (GH-32131)
https://github.com/python/cpython/commit/2bcbc3113dee6c35631595ec0d5ee3a8dd2a2ddd
msg416222 - (view) Author: miss-islington (miss-islington) Date: 2022-03-28 22:16
New changeset f84fb55659079bbc99d4cd0441dc13ab07ac3dcf by Miss Islington (bot) in branch '3.9':
bpo-27929: resolve names only for AF_INET/AF_INET6 with asyncio (GH-32131)
https://github.com/python/cpython/commit/f84fb55659079bbc99d4cd0441dc13ab07ac3dcf
History
Date User Action Args
2022-04-11 14:58:35adminsetgithub: 72116
2022-03-28 22:35:22asvetlovsetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.9, Python 3.10
2022-03-28 22:16:34miss-islingtonsetmessages: + msg416222
2022-03-28 22:15:14miss-islingtonsetmessages: + msg416220
2022-03-28 21:50:40miss-islingtonsetpull_requests: + pull_request30243
2022-03-28 21:50:36miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request30242
2022-03-28 21:50:33asvetlovsetmessages: + msg416218
2022-03-26 20:12:16ned.deilysetnosy: + asvetlov, - ned.deily
versions: + Python 3.11, - Python 3.5, Python 3.6, Python 3.7, Python 3.8
2022-03-26 18:17:19bernatsetkeywords: + patch
nosy: + bernat

pull_requests: + pull_request30211
stage: needs patch -> patch review
2021-03-15 12:02:06vstinnersetnosy: - vstinner
2021-03-15 01:08:05Guido.van.Rossumsetnosy: - gvanrossum
2021-03-14 23:37:00larrysetnosy: - larry
2021-03-14 23:33:27paulniklasweisssetversions: + Python 3.7, Python 3.8
2016-09-18 21:22:56rjordenssetmessages: + msg276916
2016-09-15 21:37:45yselivanovsetmessages: + msg276623
2016-09-02 04:30:55rjordenssetmessages: + msg274201
2016-09-01 15:32:13gvanrossumsetmessages: + msg274142
2016-09-01 14:15:16abarrysetpriority: normal -> high

type: behavior
title: asyncio.AbstractEventLoop.sock_connect brooken for AF_BLUETOOTH -> asyncio.AbstractEventLoop.sock_connect broken for AF_BLUETOOTH
keywords: + 3.5regression
nosy: + abarry, ned.deily

messages: + msg274134
stage: needs patch
2016-09-01 14:11:59rjordenssetnosy: + gvanrossum, vstinner, yselivanov
components: + asyncio, - Argument Clinic
2016-09-01 14:01:55rjordenssetmessages: + msg274132
2016-09-01 13:59:55rjordenscreate