Skip to content

Fixed deadlock when calling SendQueryAsync synchronously #332 #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/GraphQL.Client/GraphQLHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public async Task<GraphQLResponse<TResponse>> SendQueryAsync<TResponse>(GraphQLR
Options.EndPoint.HasWebSocketScheme())
return await GraphQlHttpWebSocket.SendRequest<TResponse>(request, cancellationToken);

return await SendHttpRequestAsync<TResponse>(request, cancellationToken);
return await SendHttpRequestAsync<TResponse>(request, cancellationToken)
.ConfigureAwait(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only there and not two lines above also ?

}

/// <inheritdoc />
Expand Down Expand Up @@ -143,7 +144,8 @@ private async Task<GraphQLHttpResponse<TResponse>> SendHttpRequestAsync<TRespons
var preprocessedRequest = await Options.PreprocessRequest(request, this);

using var httpRequestMessage = preprocessedRequest.ToHttpRequestMessage(Options, JsonSerializer);
using var httpResponseMessage = await HttpClient.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
using var httpResponseMessage = await HttpClient.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseHeadersRead, cancellationToken)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only there and not two lines below also ?

Copy link
Author

@ds1709 ds1709 Apr 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deadlock happens exactly because of HttpClient.SendAsync has no ConfigureAwait(false). To resolve issue #332 it's enougth to call ConfigureAwait(false) just here. But idealy whole project should be reviewed and each await should be configured. First, it will prevent from potential deadlocks, and second, it may have positive impact on performance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deadlock happens exactly because of HttpClient.SendAsync has no ConfigureAwait(false)

Could you please write a test to verify this assertion ?

Copy link
Author

@ds1709 ds1709 Apr 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you meen a unit test or just simple test application to be sure?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit test to be able to run on CI.

Copy link
Member

@sungam3r sungam3r Apr 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may call it unit or integration, whatever. The key part is to verify behavior on CI.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure there's somthing to test. Also I'm not sure it's posible to test ConfigureAwait or dedlock prevention. So I can't write it.

.ConfigureAwait(false);

var contentStream = await httpResponseMessage.Content.ReadAsStreamAsync();

Expand Down