-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question]: Clone HttpRequestMessage for each retry by altering the input with Chaos Behavior? #2521
Comments
This would be a breaking change, so no we wouldn't do this. I'll get back to you on the other questions. |
But note that it's in entirely different repository. It's an internal implementation detail of something that builds on top of Polly, not Polly itself.
Yes and no. "Altering the input" isn't specifically what it's for, it's a generic "do something here" hook. You can just happen to maybe use it to alter the input if you factor your code in a way that allows it. This is probably why we don't have a specific example of it either, because how you'd do it would vary from use-case to use-case. For example if the input was a value type (e.g. As chaos behaviours are intended to see how your code responds to unexpected behaviours at the call site, not force those behaviours into the call site, I don't think that's something we'd make a first-class feature either. Say your code called something with the value
We wouldn't rename it because:
We have that already - it's
Not to hand, and that's a concern external to Polly anyway. Polly has no dependency on anything specific to HTTP. |
OnRetry will be invoked |
To take a step back, why not just clone it before passing it to the strategy? Why do you need to pass an object in to Polly, and then have Polly then have to know you want to clone it?
It would be helpful to have a specific example of what you're actually trying to achieve here that's the motivation for this request as to why specifically you need to clone the message. If there's zero retries, then the clone would just be wasteful? |
See: |
Interesting that ASP.NET Core's Polly implementation doesn't clone the request message at any point and I'm not aware of tha having issues related to the re-use: https://github.com/dotnet/aspnetcore/tree/main/src/HttpClientFactory/Polly/src Do you have any thoughts on this @martintmk? |
Regarding the cloning, for retries this is not required as we won't have concurrent requests anyway. The only downside is that any headers added to request in the strategies bellow retries will be added for retry attempts too. One needs to be aware of such downside. For hedging, the situation is quite different as there might be multiple concurrent requests being send. In this scenario, the request must be indeed cloned to prevent race conditions. This is where the cloning happens in dotnet/extensions repo: Be aware that only request messages that do not stream content can be currently cloned. |
@martintmk I got the difference between retry & hedging you shared. But the key point is how can we use
Or should we, I mean .net team, update that Similar issue link: |
This is new to me. I was not aware of this condition. Is this just a recommendation or is there something in the HTTP stack that prevents re-sending the request again? Currently, re-sending works just fine. |
What are you wanting to achieve?
I am trying to
Clone HttpRequestMessage
for each retry then use it for next retry since some reason.From this doc https://www.pollydocs.org/chaos/behavior.html, I saw that
allowing users to define specific behaviors such as altering the input
.So, I use
AddChaosBehavior
as one hack way. The issue for this way is that:What I used is
*Chaos*
but forBeforeEachRetry
, it does not make sense from naming.Resilience.Http.RequestMessage
is internally thing. So, it is hack but quick way.https://github.com/dotnet/extensions/blob/060e3facaadeb34aa45be95aeaa8ba977e5c8772/src/Libraries/Microsoft.Extensions.Http.Resilience/Internal/ResilienceKeys.cs#L13
I can create some customized strategy to finish it but need more effort.
Question:
altering the input
in that doc.AddChaosBehavior
toAddBehavior
then it can conceptually support not just for chaos but also for resilience strategy?BeforeRetry
callback for Retry strategy?What code or approach do you have so far?
I am using this pattern
Additional context
No response
The text was updated successfully, but these errors were encountered: