Author ods
Recipients Elvis.Pranskevichus, Nikita Ilyasov, aaliddell, asvetlov, chris.jerdonek, lukasz.langa, miss-islington, ods, yselivanov
Date 2021-05-13.14:53:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The original problem can be fixed by wrapping await into try-except block:

async def create_connection(ssl_obj):
    loop = asyncio.get_event_loop()
    connector = loop.create_connection(MyEchoClientProtocol, '', 5000, ssl=ssl_obj)
    connector = asyncio.ensure_future(connector)
        tr, pr = await connector
    except asyncio.CancelledError:
        if connector.done():
            tr, pr = connector.result()
            # Uncommenting the following line fixes the problem:
            # tr.close()
    return tr, pr

I've updated my example to reproduce this:

I believe it's general problem with maintaining atomicity in async code, and not a bug in `wait_for`. Probably having an interface like `async with loop.create_connection(…) as transport, protocol` might simplify correct usage for this particular case.
Date User Action Args
2021-05-13 14:53:36odssetrecipients: + ods, asvetlov, chris.jerdonek, Elvis.Pranskevichus, lukasz.langa, yselivanov, miss-islington, Nikita Ilyasov, aaliddell
2021-05-13 14:53:36odssetmessageid: <>
2021-05-13 14:53:36odslinkissue37658 messages
2021-05-13 14:53:36odscreate