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.

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 <1620917616.4.0.310145765203.issue37658@roundup.psfhosted.org>
In-reply-to
Content
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, '127.0.0.1', 5000, ssl=ssl_obj)
    connector = asyncio.ensure_future(connector)
    try:
        tr, pr = await connector
    except asyncio.CancelledError:
        if connector.done():
            tr, pr = connector.result()
            # Uncommenting the following line fixes the problem:
            # tr.close()
        raise
    return tr, pr
```

I've updated my example to reproduce this: https://github.com/ods/bpo-37658/commit/eca3d81d60cbe129ce687674e6451836d567f6b9

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.
History
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: <1620917616.4.0.310145765203.issue37658@roundup.psfhosted.org>
2021-05-13 14:53:36odslinkissue37658 messages
2021-05-13 14:53:36odscreate