cpython icon indicating copy to clipboard operation
cpython copied to clipboard

gh-118950: Fix SSLProtocol.connection_lost not being called when OSError is thrown on asyncio.write.

Open cjavad opened this issue 1 year ago • 10 comments
trafficstars

Let _SSLProtocolTransport.is_closing reflect SSLProtocol internal transport closing state so that StreamWriter.drain will invoke sleep(0) which calls connection_lost and correctly notifies waiters of connection lost. (#118950)

In an existing comment in asyncio/streams.py there is some logic that correctly ensures that the connection_lost function is always called for users that keep writing and draining in some other context.

The issue here is that this code only runs when the transport is marked as closing, which in the case of the _SSLTransportProtocol only happened after connection_lost has been called.

My proposed fix is for _SSLTransportProtocol.is_closing to also return true when its inner transport is marked as closing, when connection_lost is called the inner transport is removed and instead the _closed flag is set.

No additional tests have been added (yet).

  • Issue: gh-118950

cjavad avatar May 12 '24 01:05 cjavad

All commit authors signed the Contributor License Agreement.
CLA signed

cpython-cla-bot[bot] avatar May 12 '24 01:05 cpython-cla-bot[bot]

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

bedevere-app[bot] avatar May 12 '24 01:05 bedevere-app[bot]

As requested @gvanrossum i've opened up a PR for #118950

cjavad avatar May 12 '24 01:05 cjavad

@kumaraditya303 Do you have time to review this? I know nothing about SSL. Who else could we ask?

gvanrossum avatar Jun 01 '24 15:06 gvanrossum

Please add some tests, I'll try to find time to review in following week.

kumaraditya303 avatar Jun 08 '24 13:06 kumaraditya303

I'm not familiar with the SSL code, but the change looks reasonable to me and certainly seems to fix the aiohttp issue (https://github.com/aio-libs/aiohttp/issues/3122).

Dreamsorcerer avatar Aug 06 '24 00:08 Dreamsorcerer

I will get around to adding some test cases in a ~~few weeks~~ today, but anyone is more than welcome to chip in, you can see my original standalone tests (especially the first one) in the issue.

Note: All tests are passing, the final check never ran due to GitHub going down.

cjavad avatar Aug 14 '24 16:08 cjavad

Is it realistic to expect this bug fix will be backported to 3.12? Or should we expect it in 3.13 or 3.14?

cjavad avatar Oct 20 '24 23:10 cjavad