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

Conversation

ds1709
Copy link

@ds1709 ds1709 commented Apr 10, 2021

The following changes fixes deadlock problem from issue #332.

  • Added ConfigureAwait(false) on SendHttpRequestAsync and HttpClient.SendAsync.

@@ -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 ?

@@ -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.

@rose-a rose-a mentioned this pull request Nov 1, 2021
@ds1709 ds1709 closed this Nov 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants