Repository navigation
Body dropped too late when an h1 handshake hits an error #4122
Description
Activity
- addedC-bugCategory: bug. Something is wrong. This is bad!Category: bug. Something is wrong. This is bad!
on Jul 2, 2026 Interesting! Yea, the now or never thing is probably from a long time ago, and probably could be improved.
Though, I'm curious about the test case that this is failing. Retrieval of the queued request is on a best-effort basis. It's possible it doesn't happen. And there's no external guarantee of drop order. So, I'm a little suspicious of a test that is depending on that. The body should drop eventually. (Though, I wonder if it's doing anything more, which is preventing the connection from dropping.)
That said, it's always better internally to recover the request than to drop it, as it can allow trying to send it again on a better connection. So I'd like to improve that, just as a secondary thing I think.
FWIW the use case within Wasmtime doesn't depend on precise ordering of anything, but rather it'd be desirable to have the property than when the only live object is the sender that all other in-flight requests are either dropped or recovered somewhere. Right now I believe there's the possibility of an in-flight request being stuck in the sender with nowhere to go but being dropped when the sender is dropped itself.
Another possible fix for us, which we're not doing yet, is to route the error from the
connpart of the handshake back into the other side somehow. Right now that's just logged and we're relying on drop behavior, but if you're saying you'd rather not guarantee the drop behavior then routing that error somewhere is what we could do instead.I reproduced this on current master. The race is between
UnboundedSender::sendreserving channel capacity and publishing the envelope:
receiver shutdown can observe an empty channel and finish in that window,
leaving the request owned by the remaining sender.I have a narrowly scoped HTTP/1 fix that serializes envelope publication with
receiver shutdown, together with a regression test that exercises the
close/send race. The 500,000-iteration stress harness went from 23 missed drops
on master to 0 with the patch. I'm finishing the last checks and will open it as
a draft shortly.- addedC-bugCategory: bug. Something is wrong. This is bad!Category: bug. Something is wrong. This is bad!and removedC-bugCategory: bug. Something is wrong. This is bad!Category: bug. Something is wrong. This is bad!
on Aug 21, 2026 - added 2 commits that reference this issue
on Aug 21, 2026 - added 2 commits that reference this issue
on Aug 30, 2026 webdevsamran commented
on Sep 6, 2026 on Sep 6, 2026 · Hidden as low-qualityshow commentMore actionsFor coordination, there is already an open PR for this issue: #4150. The current revision drains the existing receive future during shutdown rather than adding an
Arc<Mutex>, and it is waiting for maintainer re-review.Please take a look there before starting a separate implementation so we can avoid duplicating the work. An additional handshake-error reproducer would also be useful to compare against the existing regression test.
- addedC-bugCategory: bug. Something is wrong. This is bad!Category: bug. Something is wrong. This is bad!and removedC-bugCategory: bug. Something is wrong. This is bad!Category: bug. Something is wrong. This is bad!
on Oct 9, 2026 This should be fixed by #4222.
Version
hyper 1.10.1
Platform
Linux x86_64 7.0.0-27-generic
Summary
Wasmtime hit a spurious failure in a test recently in CI that I think I've diagnosed to some code in hyper. The test in question is a wasm guest that issues an HTTP/1.1 request to a server that only works with HTTP/2, and the expectation is that the wasm guest gets a
HttpProtocolErrorwithin wasm. This test ended up timing out in CI and getting a timeout failure instead.After some investigation it looks like this is due hyper's use of tokio's channels and the precise synchronization/sequencing of sending a request from one channel to another. The code in question attached here is a small program which showcases this race where the intention of the test is:
Code Sample
Expected Behavior
My expectation of this program is that the body of the request is always dropped by the time that the only live value is the sender itself. Effectively this should never print
body wasn't dropped.Actual Behavior
Locally ~2m iterations show ~20 instances of the body not being dropped before the sender is fully dropped. This is how in Wasmtime's embedding it ended up showing as a timeout because we rely on the body being dropped to register when the request is sent and such (or an error occurred).
Additional Context
Some poking and prodding around things shows that one possible culprit here is this line which is a bit more robust using Tokio's
try_recv(my guess is thattry_recvwas added after this was authored). Even with that, however, the program above still doesn't drop the body 100% of the time, and this seems due to the fact that even ifclosehas been called on a channel it's possible fortry_recvto returnEmpty(as opposed toDisconnected) if there's an outstanding permit of a message being sent. I think this is basically still a race between the sender/receiver wheretry_recvisn't enough, hyper would have to loop overtry_recv.Overall this is where I figured it'd be best to file an issue. I'd want to confirm the expectation that this program should reliably drop the body, and then also see what others' thoughts are on this.