Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
gh-118950: Fix SSLProtocol.connection_lost not being called when OSError is thrown on asyncio.write.#118960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ghost commentedMay 12, 2024 • edited by ghost
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by ghost
Uh oh!
There was an error while loading.Please reload this page.
Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
…ocol internal transport closing state so that StreamWriter.drain will invoke sleep(0) which calls connection_lost and correctly notifies waiters of connection lost. (python#118950)
cjavad commentedMay 12, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
As requested@gvanrossum i've opened up a PR for#118950 |
…e connection and cancellation and handle exceptions more gracefully. This addresses the 1006 issue.
@kumaraditya303 Do you have time to review this? I know nothing about SSL. Who else could we ask? |
Please add some tests, I'll try to find time to review in following week. |
I'm not familiar with the SSL code, but the change looks reasonable to me and certainly seems to fix the aiohttp issue (aio-libs/aiohttp#3122). |
cjavad commentedAug 14, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I will get around to adding some test cases in a Note: All tests are passing, the final check never ran due to GitHub going down. |
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
These changes look good to me.
@1st1 Double-checking with you that backporting to 3.13 and 3.12 makes sense for this PR.
Misc/NEWS.d/next/Core and Builtins/2024-05-12-03-10-36.gh-issue-118950.5Wc4vp.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
…e-118950.5Wc4vp.rst
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM, I tweaked the test a bit and the news entry.
3f24bde
intopython:mainUh oh!
There was an error while loading.Please reload this page.
Thanks@cjavad for the PR, and@kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
…n OSError is thrown (pythonGH-118960)(cherry picked from commit3f24bde)Co-authored-by: Javad Shafique <javadshafique@hotmail.com>Co-authored-by: Kumar Aditya <kumaraditya@python.org>
…n OSError is thrown (pythonGH-118960)(cherry picked from commit3f24bde)Co-authored-by: Javad Shafique <javadshafique@hotmail.com>Co-authored-by: Kumar Aditya <kumaraditya@python.org>
GH-125931 is a backport of this pull request to the3.13 branch. |
GH-125932 is a backport of this pull request to the3.12 branch. |
python/cpython#118960 has been fixed which meanscleanup closed should no longer be needed
python/cpython#118960 has been fixed anasyncio no longer leaks SSL connections
…n OSError is thrown (python#118960)Co-authored-by: Kumar Aditya <kumaraditya@python.org>
XenoAmess commentedMar 5, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
would it be backport to 3.11 & 3.10? many thanks... |
Seehttps://github.com/SimplyPrint/printer-ws-client/blob/2f52cc85f604d42d5a6728f07cc029868102ae50/simplyprint_ws_client/_polyfill.py#L16 for an example of how to patch it dynamically. |
XenoAmess commentedMar 5, 2025
thank you sincerely |
Uh oh!
There was an error while loading.Please reload this page.
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 theconnection_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).
asyncio.sslproto._SSLProtocolTransport
can experience invalid state, leading to silent failures. #118950