-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Comments
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. |
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 |
Thanks for the report! I'm unable to reproduce, as |
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. |
https://github.com/python/cpython/blob/master/Lib/asyncio/selector_events.py#L394 AF_UNIX is special-cased. |
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? |
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 |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: