OpenAPITools / OpenAPITools/openapi-generator

Retry-Policy -> The request message was already sent.

Open
#9,139 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

We are developing a Blazor (client sided) Frontend. Inside this Frontend we want to use a generated OpenAPI-Client to ease the access to our Backend.

These are the options we use to generate the client:
Version 5.1.0
csharp-netcore
target-framework net5.0
library httpclient

Works fine.

But, we also want to implement a retry-policy. Something like that:

RetryConfiguration.AsyncRetryPolicy = Policy<HttpResponseMessage>.HandleResult(rm => rm.StatusCode == System.Net.HttpStatusCode.Unauthorized).RetryAsync(1, onRetryAsync: async (response, retryCount, context)=>
{
	DoSomething()
});

Problem is:

  • first request is executed and returns 401as expected
  • DoSomething() is called
  • Retry is not possible -> The request message was already sent.

Our guess is that the error is made here (generated ApiClient.cs), and that client.SendAsync is reusing the request which is not possible.

if (RetryConfiguration.AsyncRetryPolicy != null)
{
	var policy = RetryConfiguration.AsyncRetryPolicy;
	var policyResult = await policy
		.ExecuteAndCaptureAsync(() => client.SendAsync(req, cancellationToken))
		.ConfigureAwait(false);
	response = (policyResult.Outcome == OutcomeType.Successful) ?
		policyResult.Result : new HttpResponseMessage()
		{
			ReasonPhrase = policyResult.FinalException.ToString(),
			RequestMessage = req
		};
}
else
{
	response = await client.SendAsync(req, cancellationToken).ConfigureAwait(false);
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the generated ApiClient.cs at the RetryConfiguration and client.SendAsync code shown in the issue. Reproduce the 401 retry with the C# HttpClient library and inspect whether the same request is reused; done means the configured retry can execute successfully without the already-sent-request error.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.