Skip to content

Powershell Microsoft.Graph- How to set MaxRetry #1106

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

Closed
MarkDordoy opened this issue Feb 22, 2022 · 7 comments · Fixed by #1584
Closed

Powershell Microsoft.Graph- How to set MaxRetry #1106

MarkDordoy opened this issue Feb 22, 2022 · 7 comments · Fixed by #1584
Assignees

Comments

@MarkDordoy
Copy link

Is there a way to set the max retry value for the Microsoft.Graph powershell modules.

I'm hitting an issue from time to time, where a particular cmdlet retries 3 times then fails. Ideally i'd like a way to increase this somehow. Is this supported?

This supports the theory that it is set to 3 and backs up what im seeing.

Thanks

@ghost ghost added the ToTriage label Feb 22, 2022
@peombwa
Copy link
Member

peombwa commented Feb 23, 2022

@MarkDordoy, the PowerShell SDK does currently not support this. The MaxRetry is currently locked at 3, and the implementation is based on https://microsoftgraph.github.io/msgraph-sdk-design/middleware/RetryHandler.html.

Which command are you using? Ideally, the service should respond with a retry-after header that SDK will honor.

We will consider exposing a way for customers to set their preferred MaxRetry. This will likely be through a global variable.

@peombwa peombwa added this to the v2 milestone Feb 23, 2022
@MarkDordoy
Copy link
Author

I came across this issue when using this call: Get-MgAuditLogDirectoryAudit -Filter "targetResources/any(t: t/id eq '$($user.Id)') and activityDisplayName eq 'Enable account' and activityDateTime gt $gracePeriodStr" -Top 1

Ifs fine for a while, but i was running this within a foreach-Object -Parallel script block so i guess i was hitting 429s and 3 retries was not enough (I think).

@MarkDordoy
Copy link
Author

Error that is caught:

Get-MgAuditLogDirectoryAudit_List:
Line |
  25 |  … toryAudit -Filter "targetResources/any(t: t/id eq '$($user.Id)') and  …
     |                                                         ~~~~~~~~
     | Code: tooManyRetries
Message: More than 3 retries encountered while sending the request.

It throws an exception type of Microsoft.Graph.ServiceException

$_.Exception.Error

Code            : tooManyRetries
Message         : More than 3 retries encountered while sending the request.
Target          :
Details         :
InnerError      :
ThrowSite       :
ClientRequestId :
AdditionalData  :

Stack Trace:

$_.Exception.StackTrace
   at Microsoft.Graph.RetryHandler.SendRetryAsync(HttpResponseMessage response, CancellationToken cancellationToken)
   at Microsoft.Graph.RetryHandler.SendAsync(HttpRequestMessage httpRequest, CancellationToken cancellationToken)
   at Microsoft.Graph.CompressionHandler.SendAsync(HttpRequestMessage httpRequest, CancellationToken cancellationToken)
   at Microsoft.Graph.AuthenticationHandler.SendAsync(HttpRequestMessage httpRequestMessage, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Microsoft.Graph.PowerShell.Reports.AuditLogsListDirectoryAudits_Call(HttpRequestMessage request, Func`3 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Graph.PowerShell.Reports.AuditLogsListDirectoryAudits_Call(HttpRequestMessage request, Func`3 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Graph.PowerShell.Reports.AuditLogsListDirectoryAudits(Nullable`1 Top, Nullable`1 Skip, String Search, String Filter, Nullable`1 Count, String[] Orderby, String[] Select, String[] Expand, Func`3 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Graph.PowerShell.Cmdlets.GetMgAuditLogDirectoryAudit_List.ProcessRecordAsync()```

@peombwa
Copy link
Member

peombwa commented Apr 8, 2022

Got it! We will need to allow customers to set RetriesTimeLimit global variable that they can use to control the maximum number of retries allowed. The current implementation currently locks this to 3.

@maisarissi
Copy link

@peombwa I have the impression the max retries and retry after was already covered by another PR of the v2 work you did. Just checking.

@peombwa
Copy link
Member

peombwa commented Oct 20, 2022

@maisarissi, this is still an open feature request. It hasn't been implemented in v2.

I'll expedite its implementation in v1 since it is blocking customers.

@peombwa peombwa removed this from the v2 milestone Oct 20, 2022
@ArmaanMcleod
Copy link

ArmaanMcleod commented Aug 31, 2023

Hi @peombwa. When will this be available for beta v2 commands? Or does Set-MgRequestContext work with beta v2 commands now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants