Conversation
…request The Receiver signals want when its queue reports Pending, and SendRequest::is_ready reports that want. A want signaled after finding the queue empty can land after the Sender's give() for the request that follows, and tokio's coop budget can make the queue report Pending with a request already queued. Either way the request is taken with want set, and the connection reports ready until the response completes. hyper-util's legacy pool returns connections on is_ready, so it hands a busy connection to the next request, which then waits behind the whole response. Withdraw the want with want::Taker::unwant when a request is taken. Want is signaled again once the dispatcher is idle. Requires want with Taker::unwant (seanmonstar/want#6). Closes hyperium#4207
…eased The previous commit needs want::Taker::unwant, which no want release has yet. Patch want to the PR branch so the change builds and CI can run. Replace this with a want version bump once want is released.
This was referenced Sep 28, 2026
This branch has not been deployed
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.
Closes #4207.
Draft: blocked on seanmonstar/want#6. The fix calls
want::Taker::unwant(), which no want release has yet. The second commit patches want to that PR's branch so this builds and CI can run. Once want is released, I'll replace that commit with awantversion bump and mark this ready for review.The problem
An HTTP/1
SendRequestreports ready through a shared want flag. The connection task sets it when it finds its request queue empty, andsend_requestclears it withgive()before queuing a request. The task'swant()can land after thatgive(), so the request is taken with the flag still set. There are two ways, both described in #4207:send_requestruns on another thread before the task callswant().Pendingwith the request already in it.While a request is in flight, the dispatcher doesn't poll the queue, so nothing clears the flag until the response is complete:
sequenceDiagram participant S as SendRequest participant F as want flag participant T as connection task Note over F: Want (connection idle) S->>F: give(): Want → Idle S->>T: request queued rect rgb(255, 228, 228) T->>F: want(): Idle → Want (stale) end T->>T: poll_recv: Ready(request) Note over T: writes the request and reads the response S->>F: is_ready()? true, with the request in flighthyper-util's legacy pool checks
is_ready()when a response head arrives. So it pools the busy connection, and the next request is written only after the whole previous response has been read.The fix
When
Receiver::poll_recvtakes a request, it withdraws any outstanding want withtaker.unwant(), a compare-exchange from Want to Idle. The task signals want again only when it is idle and polls an empty queue.sequenceDiagram participant S as SendRequest participant F as want flag participant T as connection task Note over F: Want (connection idle) S->>F: give(): Want → Idle S->>T: request queued T->>F: want(): Idle → Want (stale) T->>T: poll_recv: Ready(request) rect rgb(222, 245, 222) T->>F: unwant(): Want → Idle (new) end Note over T: writes the request and reads the response S->>F: is_ready()? false until the connection is idleWhen no stale want is set,
unwant()finds the flag Idle and does nothing. HTTP/2 is unaffected: itsis_ready()only checks whether the connection is closed.A sender-side reorder (queue the request, then
give()) isn't enough. The task's latewant()can still land after thegive(), and the coop path doesn't depend on the order at all.Tests
tests/h1_ready_in_flight.rsdrives the coop path deterministically, using only the public API. It drains the task's coop budget before polling the connection, so the queue returnsPendingwith a request in it. Then it checks thatis_ready()isfalseonce the request is taken.cargo test --features full --test h1_ready_in_flight: passes. With theunwant()line removed, it fails at the finalassert!(!sender.is_ready()), as it does on master.cargo test --features full: 313 passed, 0 failed, 10 ignored.rustfmt --checkis clean on the changed files.The test uses
tokio::task::coop::poll_proceed, which is public since tokio 1.47. The tokio dev-dependency is"1", and CI resolves the latest version. I can raise it to"1.47"if you'd prefer.