Draft
Fix "The request message was already sent" error when following redirects#60
Conversation
Agent-Logs-Url: https://github.com/FrendsPlatform/Frends.HTTP/sessions/d03bdb2e-288b-4c0b-ac7d-30f7c1697bf0 Co-authored-by: jefim <1387820+jefim@users.noreply.github.com>
Claude created this pull request from a session on behalf of
jefim
August 20, 2026 12:04
View session
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
A customer on HTTP/1.1 with
FollowRedirects=truereported intermittent exceptions: "The request message was already sent. Cannot send the same request message multiple times." (~24/1500 requests over 8 hours).Root cause
GetHttpRequestResponseAsyncbuilt a singleHttpRequestMessage(bound to a singleHttpContent) and dispatched it once. ASystem.Net.Http.HttpRequestMessagecan only be sent one time — once sent it sets an internal flag and any re-dispatch throws this exactInvalidOperationException. When the handler follows a 3xx redirect, or when the shared cachedHttpClient(defaultCacheHttpClient=true) internally re-dispatches under concurrency/connection churn, the same message is re-sent and the guard trips. This explains the low, environment-dependent error rate: only requests that hit a redirect or a re-dispatched connection are affected.Fix
HttpRequestMessageandHttpContentper send attempt via a content factory (Func<HttpContent>), so an internal re-send never reuses a consumed message.InvalidOperationException.httpContentdisposal infinallyaccordingly.BuildRequestMessageandSendRequestMessageAsynchelpers; behavior otherwise unchanged.Testing
RequestShouldFollowRedirectForRequestWithBodywhich POSTs a JSON body through a 307 redirect withFollowRedirects=trueand asserts the body reaches the final endpoint.dotnet test Frends.HTTP.Request.sln: 23 passed, 0 failed, 2 skipped.Test plan