Powershell Microsoft.Graph- How to set MaxRetry
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
@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.
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).
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()```
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.
@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.
@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.
Hi @peombwa. When will this be available for beta v2 commands? Or does Set-MgRequestContext work with beta v2 commands now?