Repository navigation
Conversation
When a response completes before the downstream request, the connection manager resets the stream. The HTTP/2 codec deferred that reset only on a best-effort basis: if flow control was still holding back part of the response, it reset the stream anyway with INTERNAL_ERROR and discarded the rest of the response. This is common for gRPC client-streaming and bidirectional-streaming RPCs. The connection manager now uses a new reset reason, LocalResetNoError, for the reset that ends an open request after a complete response. The HTTP/2 codec holds that reset until the response's END_STREAM has been sent, then sends RST_STREAM(NO_ERROR). The stream flush timeout limits the wait. While a reset is held, the codec drops request data and returns its flow-control window, keeps the stream's buffer memory account so that the overload manager can still reset it, and reports the pending response through wantsToWrite() so that a draining connection is not closed early. The new ServerConnectionCallbacks::onWantsToWriteCleared() lets the connection manager close a draining connection once the codec gives up on a held response outside of dispatch. Other resets, including explicit aborts and resets after a codec-detected error, keep their existing reasons and behavior. Runtime guard: envoy.reloadable_features.http2_hold_reset_until_response_sent Fixes envoyproxy#48192 Signed-off-by: Greg Greenway <[email protected]>
|
I'd like feedback on one design question before this goes further. This PR holds the reset in the HTTP/2 codec, and the connection manager finishes its stream as soon as the response has been handed to the codec, the same way HTTP/3 works today. The downside is observability: the access log and trace are written before the codec has finished sending the response, a later flush-timeout truncation only shows up in An alternative is a hybrid: keep everything in the codec as it is in this PR, but have the connection manager keep its stream as a zombie when it resets with What the hybrid would gain:
What it would cost:
Compared with #48857, the hybrid keeps the stream as a zombie rather than as an active stream. The connection manager would not need to intercept request data, schedule the reset, or special-case reset reasons, because the codec drops request data and sends the reset itself. Does the hybrid seem worth it for the observability and drain handling, or is the codec-only approach in this PR preferable? I'm happy to rework it either way. |
|
Thanks for explaining the trade-offs between the two approaches. After looking at both, I lean toward the hybrid approach. #48857 also uses a zombie stream to retain HCM state. I like that your proposal puts the HTTP/2 codec in charge of deferring the reset and handling any subsequent request DATA. That lets HCM wait until the codec finishes encoding the response or abandons the flush before it records the request end time and writes the final access log entry. I also noticed while looking at the HTTP/3 implementation that QUIC may still have response data waiting to be sent when HCM finalizes %DURATION%. If you think it’s worth adjusting when that happens, I’d be happy to open a separate issue to confirm the expected behavior and follow up with a fix. For edge-case testing, I think we can reuse a few tests from #48857. For example, if the upstream sends a reset after the upstream stream has been detached, the codec should still finish sending the complete response it already has queued. I’d also check that HCM completes cleanup in each case where the client resets the stream early, the downstream connection closes, or the flush times out, and that the same reset is only counted once. |
|
I have some availability over the next few days and would be happy to help finish #49126. |
Commit Message: http2: send the complete response before resetting an open request
When a response completes before the downstream request, the connection manager resets the stream. The HTTP/2 codec deferred that reset only on a best-effort basis: if flow control was still holding back part of the response, it reset the stream anyway with INTERNAL_ERROR and discarded the rest of the response. This is common for gRPC client-streaming and bidirectional-streaming RPCs.
The connection manager now uses a new reset reason,
LocalResetNoError, for the reset that ends an open request after a complete response. The HTTP/2 codec holds that reset until the response's END_STREAM has been sent, then sends RST_STREAM(NO_ERROR). The stream flush timeout limits the wait.Additional Description:
This is an alternative to #48857, which fixes the same issue by keeping the connection manager's stream alive until the codec finishes. This change keeps the fix in the codec instead. That is how HTTP/3 already handles this case (
EnvoyQuicServerStream::resetStream()callsStopReading()once the response is complete), and how #44749 handled the upstream half of this scenario.Details:
doEndStream()usesLocalResetNoErroronly when the response was already complete on entry (that is, when called fromendStream()) and the codec has not reported an error. Explicit aborts, protocol errors, CONNECT errors and tunnel drain-deadline resets keep their existing reasons. The HTTP/1 and HTTP/3 codecs treat the new reason likeLocalReset.pending_deferred_reset_streams_until END_STREAM is sent, the client ends or resets the stream, the flush timer fires, or the overload manager resets it. A held stream always has a flush timer when the flush timeout is non-zero. With a flush timeout of zero, the hold has no time limit, as it already does for a stream whose request is complete.wantsToWrite()now also reports held streams, socheckForDeferredClose()does not close a draining connection early. This matches the documented contract ofwantsToWrite()and what HTTP/3 already reports. The newServerConnectionCallbacks::onWantsToWriteCleared()tells the connection manager when the codec gives up on the last held stream outside of dispatch (flush timeout or overload reset). Everything else that ends a held stream happens during dispatch, after which the connection manager already re-checks.Known limitations:
MultiplexedIntegrationTest.DrainCloseAfterFlowControlledResponse*tests exclude HTTP/3 with a TODO. I plan to address it separately.This change was developed with the help of an AI coding assistant. I have reviewed and understand all of it.
Risk Level: Medium
Testing: New HTTP/2 codec unit tests (nghttp2 and oghttp2), connection manager unit tests, and raw-frame integration tests that send a response larger than the client's flow-control window with the request still open, including draining and flush-timeout cases.
Docs Changes: N/A
Release Notes: Added
changelogs/current/bug_fixes/http2__hold-reset-until-response-sent.rst.Platform Specific Features: N/A
Runtime guard:
envoy.reloadable_features.http2_hold_reset_until_response_sentFixes #48192