Skip to content

Deadlock AuthenticateRequestAsync(request) in src/Microsoft.Graph.Core/Requests/BaseRequest.cs #188

@linzomsft

Description

@linzomsft

Describe the bug

https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/blob/eba46355ab864ecea6710e254d3d6938ca2ceadf/src/Microsoft.Graph.Core/Requests/BaseRequest.cs
public async Task SendRequestAsync(
object serializableObject,
CancellationToken cancellationToken,
HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead)
...
// Only call AuthenticateRequestAsync when a custom IHttpProvider is used or our HttpProvider is used without an auth handler.
if (ShouldAuthenticateRequest())
await this.AuthenticateRequestAsync(request);

I believe this section is causing deadlock in my project. The project is on ASP.NET MVC 4. from synchronous controller. In one of the ajax call action implemented. When I write an async await function that wrap the MS Graph related logic and in the caller then i do function().Result or function().GetAwaiter().GetResult() The deadlock happened. It took me quite some time to find out where in the SDK was causing this deadlock. I was able of locate it in this line.
await this.AuthenticateRequestAsync(request);

The API i was using in graphclient.ServicePrincipals[id].Request().GetAsync()
The API i was using in graphclient.ServicePrincipals[id].Request().Owners.GetAsync()

What i did is:

  1. Added my own HttpProvider in GraphServiceCient. The httpprovider i added is actually just a wrap of the HttpProvider from the SDK. I put log statement before the SendRequest(), I notice the log statement never got hit. So i figure the deadlock was before that
  2. I read the BaseRequest.cs and found that line. await this.AuthenticateRequestAsync(request);
    So I wonder if this was causing the deadlock because every else in the client i see ConfigureAwait(false) but not that line. So i wrote my own GetAsync() function for graphclient.ServicePrincipals[id].Request().GetAsync()
    call it GetAsyncAlpha()
    in GetAsyncAlpha() i copied the exact same code and put a log statement before await this.AuthenticateRequestAsync(request);
    and after, the log statement never made it after calling await this.AuthenticateRequestAsync(request);
    Then i add ConfigureAwait(false) and GetAsyncAlpha() started working. so I am pretty sure it was this line causing the deadlock.

What i ended up doing is, because of this issue. I have to move back to use rest api instead of SDK.

AB#6918

Metadata

Metadata

Assignees

Labels

BugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions