MS Graph Api: Timeout when converting docx to pdf

Viewed 683

I get a Microsoft.Graph.ServiceExceptionwith Code: timeout Message: The request timed out. in Microsoft.Graph.Core with the following stack trace:

   at Microsoft.Graph.HttpProvider.SendRequestAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at Microsoft.Graph.HttpProvider.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at Microsoft.Graph.BaseRequest.SendRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Microsoft.Graph.BaseRequest.SendStreamRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at MyCode.cs

The server returns the following headers:

"X-CorrelationId": "605c9349-69e2-4569-acb5-ff9fec9aa887.5e6c48a9-6492-497a-857f-a373bff98f37"
"X-OneDriveMeTA-Version": "1.0.7615.29479"
"X-ErrorCode": "General_Timeout"
"X-ErrorType": "Unexpected"
"X-ErrorSource": "Service"
"X-AspNet-Version": "4.0.30319"
"X-MSEdge-Ref": "Ref A: 71954E8D2D9F46ACAE2CA0953006DE5D Ref B: VIEEDGE1811 Ref C: 2020-11-30T08:56:32Z"

Server response:

"Date": "Mon, 30 Nov 2020 08:57:24 GMT"
"StatusCode": "InternalServerError"
"RawResponseBody": "{\"error\":{\r\n  \"code\": \"generalException\",\r\n  \"message\": \"The operation has timed out.\",\r\n  \"innererror\": {\r\n    \"code\": \"General_Timeout\"\r\n  }\r\n}}"

C# code:

var queryOptions = new List<QueryOption> { new QueryOption('format', 'pdf') };
var pdf = await graphClient.Drives[folderId]
                           .Items[docxId]
                           .Content
                           .Request(queryOptions)
                           .GetAsync();

Usually this code works but every other day it times out. If it only times out once that would be ok but some users experience multiple timeouts in a row so even retrying does not help.

Is there a way to get more information about this issue? Do I have access to logs / more detailed error messages somewhere?

2 Answers
  1. In case of a lot of data that coused timeout exception, you need use in Paging. see more in: https://docs.microsoft.com/en-us/graph/paging2

  2. You can increase the time out by set it:

    graphClient.HttpProvider.OverallTimeout = TimeSpan.FromHours(1);

Both of the above options can solve your problem, but even if they do not they are a safe code for possible extreme cases.

  • Do Re-try and it workes for few, but still we see the issue.
  • Make sure the doc file is not locked or used by other users, which might be related to deadlock scenario
  • As you say with multiple users then i would suggest you to reduce the number of users in smaller numbers who're calling the API and see if it happens only due to the huge number of users making concurrent calls
  • Process the less number of docs at the time, instead of bulk. This will reduce the timeouts a lot.
  • Implement JSON batching to see if it helps to handle your scenario.
  • I see that you're using GraphClient, you can use overalltimeout property to see you can increase the timeout for the GraphClient and not for the API call.
Related