Skip to content

Conversation

@kasimov-maxim
Copy link

@kasimov-maxim kasimov-maxim commented Dec 6, 2025

Fixes #142352

Summary

When using StreamWriter.start_tls() to upgrade a connection to TLS mid-stream, any data already buffered in the StreamReader was lost. This commonly occurs when implementing servers that support the PROXY protocol.

Changes

  • Added _transfer_buffered_data_to_ssl() method to BaseEventLoop that transfers buffered data from StreamReader._buffer to SSLProtocol._incoming before the TLS handshake begins
  • Added tests for the PROXY protocol + TLS scenario

Test plan

  • Added new tests in test_streams.py
  • All asyncio tests pass
  • make patchcheck passes

@python-cla-bot
Copy link

python-cla-bot bot commented Dec 6, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

asyncio: start_tls() loses buffered data from StreamReader

1 participant