Skip to content

Commit a11c5b8

Browse files
committed
Fix sock_connect to resolve addresses (as in asyncio/CPython 3.5.2)
1 parent 9057fcb commit a11c5b8

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

uvloop/includes/stdlib.pxi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ cdef aio_ensure_future = asyncio.ensure_future
2828
cdef aio_gather = asyncio.gather
2929
cdef aio_wait = asyncio.wait
3030
cdef aio_logger = asyncio.log.logger
31-
cdef aio__check_resolved_address = asyncio.base_events._check_resolved_address
3231
cdef aio_iscoroutine = asyncio.iscoroutine
3332
cdef aio_iscoroutinefunction = asyncio.iscoroutinefunction
3433
cdef aio_BaseProtocol = asyncio.BaseProtocol

uvloop/loop.pyx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,28 +1861,23 @@ cdef class Loop:
18611861
self._add_reader(fd, handle)
18621862
return fut
18631863

1864-
def sock_connect(self, sock, address):
1864+
async def sock_connect(self, sock, address):
18651865
"""Connect to a remote socket at address.
18661866
1867-
The address must be already resolved to avoid the trap of hanging the
1868-
entire event loop when the address requires doing a DNS lookup. For
1869-
example, it must be an IP address, not a hostname, for AF_INET and
1870-
AF_INET6 address families. Use getaddrinfo() to resolve the hostname
1871-
asynchronously.
1872-
18731867
This method is a coroutine.
18741868
"""
18751869
if self._debug and sock.gettimeout() != 0:
18761870
raise ValueError("the socket must be non-blocking")
1871+
18771872
fut = self._new_future()
1878-
try:
1879-
if self._debug:
1880-
aio__check_resolved_address(sock, address)
1881-
except ValueError as err:
1882-
fut.set_exception(err)
1883-
else:
1873+
if sock.family == uv.AF_UNIX:
18841874
self._sock_connect(fut, sock, address)
1885-
return fut
1875+
await fut
1876+
return
1877+
1878+
_, _, _, _, address = (await self.getaddrinfo(*address))[0]
1879+
self._sock_connect(fut, sock, address)
1880+
await fut
18861881

18871882
def run_in_executor(self, executor, func, *args):
18881883
if aio_iscoroutine(func) or aio_iscoroutinefunction(func):

0 commit comments

Comments
 (0)