Skip to content

PS Graph requests tooManyRetries, works fine in Graph Explorer #1793

Closed

Description

@KG-droid

When requesting large datasets with the expand parameter an error is returned saying: tooManyRetries, however you can use the exact same request uri in Graph explorer and it works and almost instantly returns the data. An example uri is:

https://graph.microsoft.com/v1.0/deviceAppManagement/mobileApps?$Select=displayName,id&$expand=assignments

This uri will return the full 1k of paginated results via graph explorer rapidly, but just errors via invoke-mggraphrequest, or equivalent commands like Get-MgDeviceAppMgtMobileApp -Property 'displayName, id' -Expand 'assignments'.

If you only have sub 100 apps then it sometimes works, and other times returns that error. It seems like these modules have a built in timeout of some sort when waiting for a reply from Graph, whereby graph is still working on the request but the module gives up waiting.

Activity

  1. peombwa commented on Feb 8, 2023

    @peombwa
    Member

    tooManyRetries error code is returned when your request has been throttled by the service, and our in-built retry handler has retried the throttled request 3 times without getting a successful response. Executing the command with -Debug will show you what's happening behind the scenes.

    To change the default max retry limit of 3, use Set-MgRequestContext -MaxRetry <1-10>. See #1584 and https://github.com/microsoftgraph/msgraph-sdk-design/blob/master/middleware/RetryHandler.md for more details.

    Please review the throttling guidance at https://learn.microsoft.com/en-us/graph/throttling and service-specific limits at https://learn.microsoft.com/en-us/graph/throttling-limits#intune-device-enrollment-service-limits for best practices when calling the service.

  2. KG-droid commented on Feb 9, 2023

    @KG-droid
    Author

    tooManyRetries error code is returned when your request has been throttled by the service, and our in-built retry handler has retried the throttled request 3 times without getting a successful response. Executing the command with -Debug will show you what's happening behind the scenes.

    To change the default max retry limit of 3, use Set-MgRequestContext -MaxRetry <1-10>. See #1584 and https://github.com/microsoftgraph/msgraph-sdk-design/blob/master/middleware/RetryHandler.md for more details.

    Please review the throttling guidance at https://learn.microsoft.com/en-us/graph/throttling and service-specific limits at https://learn.microsoft.com/en-us/graph/throttling-limits#intune-device-enrollment-service-limits for best practices when calling the service.

    This request works fine in Graph Explorer though, so there should be no reason for it to have to retry. If it works in Graph Explorer it should also work via this powershell module. If it was truly a throttle and not an issue with this module why would Graph Explorer not get throttled?

  3. peombwa commented on Feb 9, 2023

    @peombwa
    Member

    Throttling is done by the service (via 429 status code), not the client. Graph Explorer is a web app, customers don't use it to make iterative requests in one go like they do in PowerShell. Naturally, requests from PowerShell will get throttled more given the number of requests we can send per second.

    Please use -Debug switch on the command to see where the 429 status code/retry-after header comes from. See https://learn.microsoft.com/en-us/powershell/microsoftgraph/troubleshooting?view=graph-powershell-1.0#using--debug.

  4. KG-droid commented on Feb 9, 2023

    @KG-droid
    Author

    This error occurs on a single request though, so if run this on its own:

    Invoke-MgGraphRequest -Method Get -Uri 'https://graph.microsoft.com/v1.0/deviceAppManagement/mobileApps?$Select=displayName,id&$expand=assignments'

    then it gets this error. So that's just that one request on its own, no iteration.

    If I use the -debug switch all it does is show me the auth settings and scope, then freezes for a while, then it gives me the same error mesage: ServiceException - Code: toomanyretries, Message: More than 3 retries encountered while sending the request.

    I should also note that I am able to use batch requests, requesting 20 apps and there assignments at a time, and that works fine, so that is around 60 batch requests of 20, in rapid succession, vs this single request that errors.

  5. peombwa commented on Feb 9, 2023

    @peombwa
    Member

    The "freeze" is happening because the command is internally retrying the throttled request whilst honoring the retry-after header we get from the service.

    Please share the complete output of the Get-MgDeviceAppMgtMobileApp -Property 'displayName, id' -Expand 'assignments' -Debug.

  6. 5 remaining items

  7. peombwa commented on Feb 9, 2023

    @peombwa
    Member

    No worries. Thanks for the output!

    This is the service throttling the request.

    Please open a service ticket/question at https://developer.microsoft.com/en-us/graph/support to have the API owner investigate why all the requests coming from your app (packaging tooling ...) are being throttled. Use Fiddler to capture the trace and share the request-id and date of the failed request in your ticket.

    In the meantime, you could:

    • try adjusting the default retry times to something > 3 - Set-MgRequestContext -MaxRetry 5.
    • use the default app that ships with the module - Connect-MgGraph -Scopes "DeviceManagementApps.ReadWrite.All". This assumes the service is throttling your app (packaging tooling ..).
  8. KG-droid commented on Feb 9, 2023

    @KG-droid
    Author

    I already logged a premier ticket via my works account, and a member of the Graph team said because its working fine in Graph Explorer the issue must be with the PowerShell module not the API :(
    I should also add that this error also occurs with the Connect-MSGraph module as well.

  9. peombwa commented on Feb 9, 2023

    @peombwa
    Member

    Sorry for the back and forth. Please share the Fiddler trace of the failing request in your ticket. The Fiddler trace will show the responses the command got from the service. See similar throttling related issues that have been tied to the service at https://learn.microsoft.com/en-us/answers/questions/381873/getting-exception-while-fetching-busy-time-from-ca.

    Also, what's the outcome of the suggested workaround above?

  10. KG-droid commented on Feb 9, 2023

    @KG-droid
    Author

    Regarding the default app, I cant use that as its not had the permission added on the Enterprise app for it. However I'm assuming that given the issue still occurs with Connect-MSGraph, answers the question that its not just my app?
    If I set the maxretry to 5, that seems to resolve the issue, but it takes longer on average than the batch method does. Graph Explorer returns the data almost instantaneously.

    They didnt do any investigation on the ticket, they asked me to check if it worked in Graph Explorer, then said log an issue on Github for the module.

  11. KG-droid commented on Feb 14, 2023

    @KG-droid
    Author

    They have reopened the ticket so I'll see what they come up with, and post here if/when it's fixed.

  12. KG-droid commented on Mar 16, 2023

    @KG-droid
    Author

    This has been accept as a bug, but apparently its not important enough to bother fixing it!

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions