Skip to content
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

RetryHandlerOption incorrect max_delay default logic #409

Open
pmcgaley opened this issue Nov 18, 2024 · 2 comments
Open

RetryHandlerOption incorrect max_delay default logic #409

pmcgaley opened this issue Nov 18, 2024 · 2 comments
Labels
Needs: Attention 👋 type:question An issue that's a question

Comments

@pmcgaley
Copy link

pmcgaley commented Nov 18, 2024

There seems to be some confusion in this code between delay (defaults to 3 seconds) and max_delay (should default to 180 seconds)

self._max_delay: float = min(delay, self.MAX_DELAY)

I'm hitting this using GraphServiceClient from msgraph. It's defaulting to max_delay of 3 seconds, resulting in limited or no retries.

Not sure if the intention is that you specify the max delay as delay in the constructor, or whether there should be delay and max_delay settings, but pretty sure it's not as intended currently.

@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Nov 18, 2024
@Ndiritu
Copy link
Contributor

Ndiritu commented Nov 24, 2024

Hi @pmcgaley, thank you for reaching out.
The RetryHandler waits the number of seconds defined by the delay parameter. This defaults to 3 secs and cannot be a value greater than 180 secs.

I agree that the internal naming of the variable within the class may be confusing, but the parameter name exposed via the constructor should communicate this.

You can change the default delay for the GraphServiceClient by customizing the HTTP client created:

options = {}
options[RetryHandlerOption.get_key()] = new RetryHandlerOption(delay: 5)
http_client = GraphClientFactory.create_with_default_middleware(options=options)
request_adapter = GraphRequestAdapter(auth_provider, http_client)
client = GraphServiceClient(request_adapter=request_adapter)

This can also be done per request by passing the same options dictionary to the request configuration parameters in the GraphServiceClient's get()/post()... methods for each API path.

Please let me know if you need any further assistance.

@Ndiritu Ndiritu added type:question An issue that's a question status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Nov 24, 2024
@Ndiritu Ndiritu moved this from Needs Triage 🔍 to Waits for author 🔁 in Kiota Nov 24, 2024
@pmcgaley
Copy link
Author

pmcgaley commented Nov 25, 2024

Hi. I don't think that's correct. The RetryHandler doesn't use that value as a wait time - it waits a time that's based either on Retry-After header, or a fallback of exponential backoff.

It stops retrying if the specified/computed retry time exceeds max_delay. And because of self._max_delay: float = min(delay, self.MAX_DELAY), if as in your example I specify a delay parameter of 5, max_delay gets set to 5. And then if the server responds with for example Retry-After: 10, that exceeds max_delay and no retry will be performed at all.

So basically the delay parameter actually specifies max_delay.

If I want it to retry for up to 180 seconds (which is theoretically the default) I actually have to specify new RetryHandler(delay=180). If I leave it unspecified, delay defaults to 3, and therefore because of the code above, max_delay is set to 3.

Hope that makes sense.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Attention 👋 type:question An issue that's a question
Projects
Status: Waits for author 🔁
Development

No branches or pull requests

2 participants