Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS Graph Api: Timeout when converting docx to pdf

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?

like image 730
Marius Avatar asked Nov 30 '20 07:11

Marius


1 Answers

  1. In case of a lot of data that coused timeout exception, you need use in Paging. see more in: https://learn.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.

like image 168
user1012506 Avatar answered Nov 19 '22 06:11

user1012506