From 82dfabefa79f50117e390b19372dac970397d554 Mon Sep 17 00:00:00 2001 From: zzzprojects Date: Mon, 3 Oct 2016 11:24:07 -0400 Subject: [PATCH] Fixing Async Deadlock Adding missing ConfigureAwait + put on single line await & ConfigureAwait --- Octokit/Clients/Enterprise/EnterpriseProbe.cs | 2 +- Octokit/Clients/MigrationsClient.cs | 8 +++---- Octokit/Clients/PullRequestsClient.cs | 6 ++--- Octokit/Clients/RepoCollaboratorsClient.cs | 4 ++-- Octokit/Clients/StatisticsClient.cs | 24 +++++++------------ Octokit/Http/HttpClientAdapter.cs | 2 +- 6 files changed, 18 insertions(+), 28 deletions(-) diff --git a/Octokit/Clients/Enterprise/EnterpriseProbe.cs b/Octokit/Clients/Enterprise/EnterpriseProbe.cs index fa350c0b7e..3ea5bd48e8 100644 --- a/Octokit/Clients/Enterprise/EnterpriseProbe.cs +++ b/Octokit/Clients/Enterprise/EnterpriseProbe.cs @@ -77,7 +77,7 @@ public async Task Probe(Uri enterpriseBaseUrl) IResponse response; try { - response = await httpClient.Send(request); + response = await httpClient.Send(request).ConfigureAwait(false); } catch (ApiException ex) { diff --git a/Octokit/Clients/MigrationsClient.cs b/Octokit/Clients/MigrationsClient.cs index 18a8f4d24c..532922f977 100644 --- a/Octokit/Clients/MigrationsClient.cs +++ b/Octokit/Clients/MigrationsClient.cs @@ -36,7 +36,7 @@ public async Task Start(string org, StartMigrationRequest migration) var endpoint = ApiUrls.EnterpriseMigrations(org); - return await ApiConnection.Post(endpoint, migration, AcceptHeaders.MigrationsApiPreview); + return await ApiConnection.Post(endpoint, migration, AcceptHeaders.MigrationsApiPreview).ConfigureAwait(false); } /// @@ -53,7 +53,7 @@ public async Task> GetAll(string org) var endpoint = ApiUrls.EnterpriseMigrations(org); - return await ApiConnection.Get>(endpoint, null, AcceptHeaders.MigrationsApiPreview); + return await ApiConnection.Get>(endpoint, null, AcceptHeaders.MigrationsApiPreview).ConfigureAwait(false); } /// @@ -71,7 +71,7 @@ public async Task Get(string org, int id) var endpoint = ApiUrls.EnterpriseMigrationById(org, id); - return await ApiConnection.Get(endpoint, null, AcceptHeaders.MigrationsApiPreview); + return await ApiConnection.Get(endpoint, null, AcceptHeaders.MigrationsApiPreview).ConfigureAwait(false); } /// @@ -88,7 +88,7 @@ public async Task GetArchive(string org, int id) Ensure.ArgumentNotNullOrEmptyString(org, "org"); var endpoint = ApiUrls.EnterpriseMigrationArchive(org, id); - var response = await Connection.Get(endpoint, null, AcceptHeaders.MigrationsApiPreview); + var response = await Connection.Get(endpoint, null, AcceptHeaders.MigrationsApiPreview).ConfigureAwait(false); return response.Body; } diff --git a/Octokit/Clients/PullRequestsClient.cs b/Octokit/Clients/PullRequestsClient.cs index cbc52b658a..dad64321b6 100644 --- a/Octokit/Clients/PullRequestsClient.cs +++ b/Octokit/Clients/PullRequestsClient.cs @@ -259,8 +259,7 @@ public async Task Merge(string owner, string name, int number, try { var endpoint = ApiUrls.MergePullRequest(owner, name, number); - return await ApiConnection.Put(endpoint, mergePullRequest, null, - AcceptHeaders.SquashCommitPreview).ConfigureAwait(false); + return await ApiConnection.Put(endpoint, mergePullRequest, null, AcceptHeaders.SquashCommitPreview).ConfigureAwait(false); } catch (ApiException ex) { @@ -292,8 +291,7 @@ public async Task Merge(long repositoryId, int number, MergePu try { var endpoint = ApiUrls.MergePullRequest(repositoryId, number); - return await ApiConnection.Put(endpoint, mergePullRequest, null, - AcceptHeaders.SquashCommitPreview).ConfigureAwait(false); + return await ApiConnection.Put(endpoint, mergePullRequest, null, AcceptHeaders.SquashCommitPreview).ConfigureAwait(false); } catch (ApiException ex) { diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index 34a2dc306e..4eda7655a5 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -176,7 +176,7 @@ public async Task Add(string owner, string name, string user, Collaborator try { - var response = await Connection.Put(ApiUrls.RepoCollaborator(owner, name, user), permission); + var response = await Connection.Put(ApiUrls.RepoCollaborator(owner, name, user), permission).ConfigureAwait(false); return response.HttpResponse.IsTrue(); } catch @@ -217,7 +217,7 @@ public async Task Add(long repositoryId, string user, CollaboratorRequest try { - var response = await Connection.Put(ApiUrls.RepoCollaborator(repositoryId, user), permission); + var response = await Connection.Put(ApiUrls.RepoCollaborator(repositoryId, user), permission).ConfigureAwait(false); return response.HttpResponse.IsTrue(); } catch diff --git a/Octokit/Clients/StatisticsClient.cs b/Octokit/Clients/StatisticsClient.cs index d27334168d..530ed029cc 100644 --- a/Octokit/Clients/StatisticsClient.cs +++ b/Octokit/Clients/StatisticsClient.cs @@ -100,8 +100,7 @@ public async Task GetCommitActivity(string owner, string name, C Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - var activity = await ApiConnection.GetQueuedOperation( - ApiUrls.StatsCommitActivity(owner, name), cancellationToken).ConfigureAwait(false); + var activity = await ApiConnection.GetQueuedOperation(ApiUrls.StatsCommitActivity(owner, name), cancellationToken).ConfigureAwait(false); return new CommitActivity(activity); } @@ -112,8 +111,7 @@ public async Task GetCommitActivity(string owner, string name, C /// A token used to cancel this potentially long running request public async Task GetCommitActivity(long repositoryId, CancellationToken cancellationToken) { - var activity = await ApiConnection.GetQueuedOperation( - ApiUrls.StatsCommitActivity(repositoryId), cancellationToken).ConfigureAwait(false); + var activity = await ApiConnection.GetQueuedOperation(ApiUrls.StatsCommitActivity(repositoryId), cancellationToken).ConfigureAwait(false); return new CommitActivity(activity); } @@ -150,8 +148,7 @@ public async Task GetCodeFrequency(string owner, string name, Can Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - var rawFrequencies = await ApiConnection.GetQueuedOperation( - ApiUrls.StatsCodeFrequency(owner, name), cancellationToken).ConfigureAwait(false); + var rawFrequencies = await ApiConnection.GetQueuedOperation(ApiUrls.StatsCodeFrequency(owner, name), cancellationToken).ConfigureAwait(false); return new CodeFrequency(rawFrequencies); } @@ -162,8 +159,7 @@ public async Task GetCodeFrequency(string owner, string name, Can /// A token used to cancel this potentially long running request public async Task GetCodeFrequency(long repositoryId, CancellationToken cancellationToken) { - var rawFrequencies = await ApiConnection.GetQueuedOperation( - ApiUrls.StatsCodeFrequency(repositoryId), cancellationToken).ConfigureAwait(false); + var rawFrequencies = await ApiConnection.GetQueuedOperation(ApiUrls.StatsCodeFrequency(repositoryId), cancellationToken).ConfigureAwait(false); return new CodeFrequency(rawFrequencies); } @@ -200,8 +196,7 @@ public async Task GetParticipation(string owner, string name, Can Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - var result = await ApiConnection.GetQueuedOperation( - ApiUrls.StatsParticipation(owner, name), cancellationToken).ConfigureAwait(false); + var result = await ApiConnection.GetQueuedOperation(ApiUrls.StatsParticipation(owner, name), cancellationToken).ConfigureAwait(false); return result.FirstOrDefault(); } @@ -212,8 +207,7 @@ public async Task GetParticipation(string owner, string name, Can /// A token used to cancel this potentially long running request public async Task GetParticipation(long repositoryId, CancellationToken cancellationToken) { - var result = await ApiConnection.GetQueuedOperation( - ApiUrls.StatsParticipation(repositoryId), cancellationToken).ConfigureAwait(false); + var result = await ApiConnection.GetQueuedOperation(ApiUrls.StatsParticipation(repositoryId), cancellationToken).ConfigureAwait(false); return result.FirstOrDefault(); } @@ -250,8 +244,7 @@ public async Task GetPunchCard(string owner, string name, Cancellatio Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - var punchCardData = await ApiConnection.GetQueuedOperation( - ApiUrls.StatsPunchCard(owner, name), cancellationToken).ConfigureAwait(false); + var punchCardData = await ApiConnection.GetQueuedOperation(ApiUrls.StatsPunchCard(owner, name), cancellationToken).ConfigureAwait(false); return new PunchCard(punchCardData); } @@ -262,8 +255,7 @@ public async Task GetPunchCard(string owner, string name, Cancellatio /// A token used to cancel this potentially long running request public async Task GetPunchCard(long repositoryId, CancellationToken cancellationToken) { - var punchCardData = await ApiConnection.GetQueuedOperation( - ApiUrls.StatsPunchCard(repositoryId), cancellationToken).ConfigureAwait(false); + var punchCardData = await ApiConnection.GetQueuedOperation(ApiUrls.StatsPunchCard(repositoryId), cancellationToken).ConfigureAwait(false); return new PunchCard(punchCardData); } } diff --git a/Octokit/Http/HttpClientAdapter.cs b/Octokit/Http/HttpClientAdapter.cs index d97092f6ec..24c56cca34 100644 --- a/Octokit/Http/HttpClientAdapter.cs +++ b/Octokit/Http/HttpClientAdapter.cs @@ -174,7 +174,7 @@ protected virtual void Dispose(bool disposing) public async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { // Clone the request/content incase we get a redirect - var clonedRequest = await CloneHttpRequestMessageAsync(request); + var clonedRequest = await CloneHttpRequestMessageAsync(request).ConfigureAwait(false); // Send initial response var response = await _http.SendAsync(request, HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);