fix(load): release completion handle when the response future resolves to Err#873
Open
ameyypawar wants to merge 2 commits into
Open
fix(load): release completion handle when the response future resolves to Err#873ameyypawar wants to merge 2 commits into
ameyypawar wants to merge 2 commits into
Conversation
`TrackCompletionFuture::poll` only took the load-tracking handle on the success path (`ready!(..)?` returned early on error), so a failed response kept its handle alive until the future object was dropped. That made `PendingRequests` overcount failed requests as still pending and delayed `PeakEwma`'s RTT sample until drop time. Match on the polled result and take/drop the handle on both branches, so both load metrics are updated as soon as the response future resolves, regardless of outcome. Add a `PendingRequests` regression test covering the error path.
Verify that a failed response stops contributing to PeakEwma load as soon as the response future resolves, rather than only when the future is dropped.
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.
Summary
Fixes #858.
TrackCompletionFuture::pollonly took the load-trackingHandleon the success path:When the inner response future resolved to
Err,?returned beforehandle.take()ran, so theHandlestayed alive until the outer future object was dropped rather than when the request actually completed. BothPendingRequestsandPeakEwmatrack load through thisHandle'sDrop, so a failed request kept counting as pending — and, forPeakEwma, delayed its RTT sample — until drop time. Callers that hold onto completed error futures (logging, retries, batching) can therefore make an endpoint look busier or slower than it really is.Fix
Match on the polled result and release the handle on both branches:
The success path is unchanged (the
Okarm is identical to the previous two lines); only the error path's timing changes — the handle is now released as soon as the response future resolves, regardless of outcome. This single change fixes bothPendingRequestsandPeakEwma, since both route their futures throughTrackCompletionFuture.Dropping the handle (rather than forwarding it) is the only option on the error path:
TrackCompletion::track_completion(&self, handle, value: V)requires the success valueV, which doesn't exist onErr. A handle can therefore only ever be forwarded into a successful response; on error, the RAIIDropis the intended completion signal.One thing worth a maintainer's eye: as before,
PeakEwmarecords an RTT sample for failed requests when the handle drops — this PR only corrects when that happens (at response completion instead of at future-drop). If folding failed-request latencies into the EWMA is undesirable, that's a separate change.Tests
Adds a
PendingRequestsregression test (failed_response_completes_immediately) asserting that load returns toCount(0)as soon as the failed response future resolves, while the future is still held. It fails before this change and passes after.