Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions asyncpg/connect_utils.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -508,9 +508,15 @@ async def _connect_addr(*, addr, loop, timeout, params, config,
else:
connector = loop.create_connection(proto_factory, *addr)

connector = asyncio.ensure_future(connector)

before = time.monotonic()
tr, pr = await asyncio.wait_for(
connector, timeout=timeout, loop=loop)
try:
tr, pr = await asyncio.wait_for(
connector, timeout=timeout, loop=loop)
except asyncio.CancelledError:
connector.add_done_callback(_close_leaked_connection)
raise
timeout -= time.monotonic() - before

try:
Expand DownExpand Up@@ -646,3 +652,12 @@ def _create_future(loop):
return asyncio.Future(loop=loop)
else:
return create_future()


def _close_leaked_connection(fut):
try:
tr, pr = fut.result()
if tr:
tr.close()
except asyncio.CancelledError:
pass # hide the exception