fix: retry close_notify in poll_shutdown when the send buffer is full - #78
Open
ArniDagur wants to merge 1 commit into
Open
fix: retry close_notify in poll_shutdown when the send buffer is full#78ArniDagur wants to merge 1 commit into
close_notify in poll_shutdown when the send buffer is full#78ArniDagur wants to merge 1 commit into
Conversation
`poll_shutdown` marked the write side closed _before_ enforcing a successful `close_notify`. With a full send buffer this resulted in two bugs: 1. Shutdown failed with `WouldBlock`, which is an error type that should not escape a poll-based API. 2. Subsequent retries of the shutdown skipped the `close_notify` entirely, since `write_closed` was already set. We fix this by only marking the write side closed once the alert is sent (or has failed fatally), and retrying on `WouldBlock`. The retry uses a new `AsyncWriteReady` trait, which mirrors the preexisting `AsyncReadReady`. It exposes tokio's `poll_write_ready` and `try_io`. The latter `try_write_io` clears write-readiness when `send_close_notify` returns `WouldBlock`, so the task parks until the socket becomes writable instead of [busy-polling][1]. [1]: https://github.com/rustls/ktls/blob/5e3c7d6ceadbb1ae98d06908d559490723899aed/ktls/src/ktls_stream.rs#L268-L277 This PR introduces a minor breaking change, since the `AsyncWrite` impl for `KtlsStream<IO>` now requires `IO: AsyncWriteReady`. This change also lays the foundation for additional work, including in relation to properly implementing `KeyUpdate`.
ArniDagur
force-pushed
the
fix-shutdown-close-notify-retry
branch
from
August 8, 2026 15:04
ee2dae6 to
e862e48
Compare
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.
poll_shutdownmarked the write side closed before enforcing a successfulclose_notify. With a full send buffer this resulted in two bugs:WouldBlock, which is an error type that should not escape a poll-based API.close_notifyentirely, sincewrite_closedwas already set.We fix this by only marking the write side closed once the alert is sent (or has failed fatally), and retrying on
WouldBlock.The retry uses a new
AsyncWriteReadytrait, which mirrors the preexistingAsyncReadReady. It exposes tokio'spoll_write_readyandtry_io. The latter clears write-readiness whensend_close_notifyreturnsWouldBlock, so the task parks until the socket becomes writable instead of busy-polling.This PR introduces a minor breaking change, since the
AsyncWriteimpl forKtlsStream<IO>now requiresIO: AsyncWriteReady. This change also lays the foundation for additional work, including in relation to properly implementingKeyUpdate(which I plan on doing).