Docs: Why do you change the handler lifetime?

Created on 20 Aug 2019  Â·  5Comments  Â·  Source: dotnet/docs

The line in the first code block under the section "Configure a client with Polly’s Retry policy, in Startup" .SetHandlerLifetime(TimeSpan.FromMinutes(5)) //Set lifetime to five minutes, I'm not sure why it's needed. If it is, could there be a line explaining why, if not maybe remove it?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

guide - .NET Microservices Area - .NET Architecture Guide Area - .NET Guide Pri2 dotnet-ebooktech dotneprod product-question

Most helpful comment

Hi @stoksc,

The need for the HttpHandler to have a finite lifetime is to ensure changes in DNS are handled within a "reasonable" time frame.

So, if IP address of a server changes, then the clients (using the "ethernal" HttpHandlers) would not be able to connect again to that server, because they'd be trying to use the old address.

DNS changes on servers occur in failover scenarios as you can read in this interesting discussion: https://github.com/dotnet/corefx/issues/11224 and more specifically in this comment on the same dicussion: https://github.com/dotnet/corefx/issues/11224#issuecomment-270465613.

Anyway, you can get more information related to this in the Use HttpClientFactory to implement resilient HTTP requests article in this guide.

So that's why a Lifetime is needed. As for why changing it, as usual, it all depends on the context, so you need to have the option to change it.

Hope this helps.

All 5 comments

Hi @stoksc,

The need for the HttpHandler to have a finite lifetime is to ensure changes in DNS are handled within a "reasonable" time frame.

So, if IP address of a server changes, then the clients (using the "ethernal" HttpHandlers) would not be able to connect again to that server, because they'd be trying to use the old address.

DNS changes on servers occur in failover scenarios as you can read in this interesting discussion: https://github.com/dotnet/corefx/issues/11224 and more specifically in this comment on the same dicussion: https://github.com/dotnet/corefx/issues/11224#issuecomment-270465613.

Anyway, you can get more information related to this in the Use HttpClientFactory to implement resilient HTTP requests article in this guide.

So that's why a Lifetime is needed. As for why changing it, as usual, it all depends on the context, so you need to have the option to change it.

Hope this helps.

Thanks for the response. I understand the reason you'd usually need to change it, I was wasn't sure if it was changed for any reason _in this example_. It seemed superfluous to the purpose of the docs so (even though I was pretty sure I already understood lifetime) I just wanted to make sure it wasn't some weird work around to do with using Polly.

Answer helps me understand it better though so thanks!

Great @stoksc, glad this could help you somehow!

So I'm closing this issue now but feel free to comment, will reopen if needed.

The default lifetime is 2 min. So, the example code changes the lifetime from 2 min to 5 min. I guess it's because the retry policy might keep trying for more than 2 min? 🤔 The docs doesn't really say why the lifetime is extended by 3 min.

@mvelosop can you speak to why the default lifetime needs to be increased by 150% ? If @OskarKlintrot is correct, then two minutes of hitting the wrong address sounds better than 5 minutes of hitting the wrong address.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JagathPrasad picture JagathPrasad  Â·  3Comments

FrancescoBonizzi picture FrancescoBonizzi  Â·  3Comments

ygoe picture ygoe  Â·  3Comments

LJ9999 picture LJ9999  Â·  3Comments

Manoj-Prabhakaran picture Manoj-Prabhakaran  Â·  3Comments