gh-142352: Fix start_tls() to transfer buffered data from StreamReader#142354
Conversation
Sorry, something went wrong.
Sorry, something went wrong.
picnixz
left a comment
There was a problem hiding this comment.
Has this PR been generated using an LLM? if so, indicate which places were so and read https://devguide.python.org/getting-started/generative-ai/.
Sorry, something went wrong.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Sorry, something went wrong.
|
Also, I think reading and checking if we're compliant with https://datatracker.ietf.org/doc/html/rfc2817 should be done (even if the RFC is only proposed and not in the standard tracks) or whatever RFC should be considered (I do think it's correct to fix this but I don't know if we should only send the possible hello for tls or generally write whatever was buffered) |
Sorry, something went wrong.
Noted in PR. |
Sorry, something went wrong.
RFC 2817 isn’t relevant here; it covers HTTP/1.1 Upgrade rather than |
Sorry, something went wrong.
b2ed3c3 to
86d80bf
Compare
January 21, 2026 16:08
|
I have made the requested changes; please review again |
Sorry, something went wrong.
|
Thanks for making the requested changes! @picnixz: please review the changes made to this pull request. |
Sorry, something went wrong.
86d80bf to
c2cd20b
Compare
January 21, 2026 16:49
The new regression test (test_start_tls_buffered_data) shows the trigger is broader than “ClientHello in the same TCP segment as some application flag.” The issue is any buffered TLS data that reaches StreamReader before start_tls() is called. That can happen even without proxy‑protocol or segment coalescing. |
Sorry, something went wrong.
|
Please resolve the Github comments once they are addressed, otherwise it makes reviewing difficult. |
Sorry, something went wrong.
fantix
left a comment
There was a problem hiding this comment.
LGTM!
Sorry, something went wrong.
0598f4a
into
python:main
Feb 28, 2026
|
Thanks @kasimov-maxim for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
Sorry, something went wrong.
…a from StreamReader (pythonGH-142354) (cherry picked from commit 0598f4a) Co-authored-by: Maksym Kasimov <39828623+kasimov-maxim@users.noreply.github.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org>
|
Sorry, @kasimov-maxim and @kumaraditya303, I could not cleanly backport this to |
Sorry, something went wrong.
…red data from StreamReader (pythonGH-142354) (cherry picked from commit 0598f4a) Co-authored-by: Maksym Kasimov <39828623+kasimov-maxim@users.noreply.github.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org>
…a from StreamReader (pythonGH-142354) (cherry picked from commit 0598f4a) Co-authored-by: Maksym Kasimov <39828623+kasimov-maxim@users.noreply.github.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org>
…a from StreamReader (python#142354) Co-authored-by: Kumar Aditya <kumaraditya@python.org>
…ta from StreamReader (GH-142354) (#145363) gh-142352: Fix `asyncio` `start_tls()` to transfer buffered data from StreamReader (GH-142354) (cherry picked from commit 0598f4a) Co-authored-by: Kumar Aditya <kumaraditya@python.org> Co-authored-by: Maksym Kasimov <39828623+kasimov-maxim@users.noreply.github.com>
…a from StreamReader (python#142354) Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Fixes #142352
Summary
When using
StreamWriter.start_tls()to upgrade a connection to TLS mid-stream, any data already buffered in theStreamReaderwas lost. This commonly occurs when implementing servers that support the PROXY protocol.Changes
_transfer_buffered_data_to_ssl()method toBaseEventLoopthat transfers buffered data fromStreamReader._buffertoSSLProtocol._incomingbefore the TLS handshake beginsGenerative AI usage
Some parts of this PR were assisted by a generative AI tool. Specifically:
All functional logic and final edits were reviewed, verified, and authored by
me, in accordance with the Python devguide guidelines.
Test plan
test_streams.pymake patchcheckpasses