Skip to content

Powershell Microsoft.Graph- How to set MaxRetry #1106

Closed

Description

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

Activity

  1. peombwa commented on Feb 23, 2022

    @peombwa
    Member

    Mark Dordoy (@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.

  2. added this to the v2 milestone on Feb 23, 2022
  3. MarkDordoy commented on Feb 25, 2022

    @MarkDordoy
    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).

  4. MarkDordoy commented on Feb 25, 2022

    @MarkDordoy
    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()```
  5. peombwa commented on Apr 8, 2022

    @peombwa
    Member

    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.

  6. maisarissi commented on Oct 14, 2022

    @maisarissi

    Peter Ombwa (@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.

  7. peombwa commented on Oct 20, 2022

    @peombwa
    Member

    Maísa Rissi (@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.

  8. removed this from the v2 milestone on Oct 20, 2022
  9. ArmaanMcleod commented on Aug 31, 2023

    @ArmaanMcleod

    Hi Peter Ombwa (@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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions