Repository navigation
Let writes wait when a renegotiation meets application data - #320
Merged
Merged
Conversation
During a peer-initiated renegotiation, mbedtls_ssl_write returns MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO when it reads application data while waiting for the ServerHello, and keeps that data for the next read. The write path treated it as fatal: it abandoned the connection, so the reader lost data and the server saw EOF. The writer now waits until a reader has taken the held data, then retries. (Just retrying would count the held record against renego_max_records each time and fail.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #320 +/- ##
==========================================
+ Coverage 88.93% 88.99% +0.06%
==========================================
Files 12 12
Lines 904 909 +5
==========================================
+ Hits 804 809 +5
Misses 100 100 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #317. During a peer-initiated renegotiation (opt-in via
ssl_conf_renegotiation!),mbedtls_ssl_writereturnsMBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGOwhen it reads application data while waiting for the ServerHello. mbedtls keeps that data for the next read;mbedtls_ssl_readtreats the code as normal. The write path treated it as fatal: it abandoned the connection, so the reader lost the data and the server saw EOF (SSL - Unexpected message at ServerHello in renegotiation).The writer now waits until a reader has taken the held data (
ssl_check_pendingturns false), then retries. Simply retrying is wrong: eachssl_writewould read the held record again and count it againstrenego_max_records(16), failing within ~16 ms.Trade-off: with no task reading, such a write now waits until something reads the data or the connection closes, instead of failing. HTTP.jl reads and writes concurrently, and doesn't enable renegotiation.
New testset: the server requests renegotiation and keeps sending; the client's reader takes the first byte and pauses while the client writes. Master: the write throws and the reader gets only
"A". With this change:"ping"arrives, and the reader gets"ABC". It passed 3/3 locally.Found by a fourth independent review pass; reproduced and checked here.
🤖 Generated with Claude Code