Skip to content

Commit

Permalink
Fixes #153 by adding ConfigureAwait(false) to all await points in the…
Browse files Browse the repository at this point in the history
… library
  • Loading branch information
stegus64 committed Aug 2, 2019
1 parent fd67f42 commit 0b2f1d6
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions Snowflake.Data/Client/SnowflakeDbCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public override async Task<int> ExecuteNonQueryAsync(CancellationToken cancellat
if (cancellationToken.IsCancellationRequested)
throw new TaskCanceledException();

var resultSet = await ExecuteInternalAsync(cancellationToken);
var resultSet = await ExecuteInternalAsync(cancellationToken).ConfigureAwait(false);
return resultSet.CalculateUpdateCount();
}

Expand All @@ -187,9 +187,9 @@ public override async Task<object> ExecuteScalarAsync(CancellationToken cancella
if (cancellationToken.IsCancellationRequested)
throw new TaskCanceledException();

var result = await ExecuteInternalAsync(cancellationToken);
var result = await ExecuteInternalAsync(cancellationToken).ConfigureAwait(false);

if(await result.NextAsync())
if(await result.NextAsync().ConfigureAwait(false))
return result.GetValue(0);
else
return DBNull.Value;
Expand All @@ -215,7 +215,7 @@ protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
protected override async Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
{
logger.Debug($"ExecuteDbDataReaderAsync, command: {CommandText}");
var result = await ExecuteInternalAsync(cancellationToken);
var result = await ExecuteInternalAsync(cancellationToken).ConfigureAwait(false);
return new SnowflakeDbDataReader(this, result);
}

Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data/Core/Authenticator/BasicAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async Task IAuthenticator.AuthenticateAsync(CancellationToken cancellationToken)
{
var loginRequest = BuildLoginRequest();

var response = await session.restRequester.PostAsync<LoginResponse>(loginRequest, cancellationToken);
var response = await session.restRequester.PostAsync<LoginResponse>(loginRequest, cancellationToken).ConfigureAwait(false);

session.ProcessLoginResponse(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async Task IAuthenticator.AuthenticateAsync(CancellationToken cancellationToken)
await session.restRequester.PostAsync<AuthenticatorResponse>(
authenticatorRestRequest,
cancellationToken
);
).ConfigureAwait(false);
authenticatorRestResponse.FilterFailedResponse();

var idpUrl = authenticatorRestResponse.data.ssoUrl;
Expand All @@ -71,15 +71,15 @@ await session.restRequester.PostAsync<AuthenticatorResponse>(
StartBrowser(idpUrl);

logger.Debug("Get the redirect SAML request");
var context = await httpListener.GetContextAsync();
var context = await httpListener.GetContextAsync().ConfigureAwait(false);
var request = context.Request;
samlResponseToken = ValidateAndExtractToken(request);
HttpListenerResponse response = context.Response;
try
{
using (var output = response.OutputStream)
{
await output.WriteAsync(SUCCESS_RESPONSE, 0, SUCCESS_RESPONSE.Length);
await output.WriteAsync(SUCCESS_RESPONSE, 0, SUCCESS_RESPONSE.Length).ConfigureAwait(false);
}
}
catch (Exception e)
Expand All @@ -95,7 +95,7 @@ await session.restRequester.PostAsync<AuthenticatorResponse>(
var loginResponse = await session.restRequester.PostAsync<LoginResponse>(
BuildExternalBrowserLoginRequest(samlResponseToken, proofKey),
cancellationToken
);
).ConfigureAwait(false);
session.ProcessLoginResponse(loginResponse);
}

Expand Down
10 changes: 5 additions & 5 deletions Snowflake.Data/Core/Authenticator/OktaAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async Task IAuthenticator.AuthenticateAsync(CancellationToken cancellationToken)

logger.Debug("step 1: get sso and token url");
var authenticatorRestRequest = BuildAuthenticatorRestRequest();
var authenticatorResponse = await session.restRequester.PostAsync<AuthenticatorResponse>(authenticatorRestRequest, cancellationToken);
var authenticatorResponse = await session.restRequester.PostAsync<AuthenticatorResponse>(authenticatorRestRequest, cancellationToken).ConfigureAwait(false);
authenticatorResponse.FilterFailedResponse();
Uri ssoUrl = new Uri(authenticatorResponse.data.ssoUrl);
Uri tokenUrl = new Uri(authenticatorResponse.data.tokenUrl);
Expand All @@ -61,20 +61,20 @@ async Task IAuthenticator.AuthenticateAsync(CancellationToken cancellationToken)

logger.Debug("step 3: get idp onetime token");
IdpTokenRestRequest idpTokenRestRequest = BuildIdpTokenRestRequest(tokenUrl);
var idpResponse = await session.restRequester.PostAsync<IdpTokenResponse>(idpTokenRestRequest, cancellationToken);
var idpResponse = await session.restRequester.PostAsync<IdpTokenResponse>(idpTokenRestRequest, cancellationToken).ConfigureAwait(false);
string onetimeToken = idpResponse.CookieToken;

logger.Debug("step 4: get SAML reponse from sso");
var samlRestRequest = BuildSAMLRestRequest(ssoUrl, onetimeToken);
var samlRawResponse = await session.restRequester.GetAsync(samlRestRequest, cancellationToken);
var samlRawHtmlString = await samlRawResponse.Content.ReadAsStringAsync();
var samlRawResponse = await session.restRequester.GetAsync(samlRestRequest, cancellationToken).ConfigureAwait(false);
var samlRawHtmlString = await samlRawResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

logger.Debug("step 5: verify postback url in SAML reponse");
VerifyPostbackUrl(samlRawHtmlString);

logger.Debug("step 6: send SAML reponse to snowflake to login");
var loginRestRequest = BuildOktaLoginRestRequest(samlRawHtmlString);
var authnResponse = await session.restRequester.PostAsync<LoginResponse>(loginRestRequest, cancellationToken);
var authnResponse = await session.restRequester.PostAsync<LoginResponse>(loginRestRequest, cancellationToken).ConfigureAwait(false);
session.ProcessLoginResponse(authnResponse);
}

Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data/Core/HttpUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
}

response = await base.SendAsync(requestMessage, childCts == null ?
cancellationToken : childCts.Token);
cancellationToken : childCts.Token).ConfigureAwait(false);
}
catch(Exception e)
{
Expand Down
10 changes: 5 additions & 5 deletions Snowflake.Data/Core/RestRequester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public async Task<T> PostAsync<T>(IRestRequest request, CancellationToken cancel
{
var req = request.ToRequestMessage(HttpMethod.Post);

var response = await SendAsync(req, request.GetRestTimeout(), cancellationToken);
var json = await response.Content.ReadAsStringAsync();
var response = await SendAsync(req, request.GetRestTimeout(), cancellationToken).ConfigureAwait(false);
var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
logger.Debug($"Post response: {json}");
return JsonConvert.DeserializeObject<T>(json);
}
Expand All @@ -69,8 +69,8 @@ public T Get<T>(IRestRequest request)

public async Task<T> GetAsync<T>(IRestRequest request, CancellationToken cancellationToken)
{
HttpResponseMessage response = await GetAsync(request, cancellationToken);
var json = await response.Content.ReadAsStringAsync();
HttpResponseMessage response = await GetAsync(request, cancellationToken).ConfigureAwait(false);
var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
logger.Debug($"Get response: {json}");
return JsonConvert.DeserializeObject<T>(json);
}
Expand Down Expand Up @@ -103,7 +103,7 @@ private async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,

try
{
var response = await HttpUtil.getHttpClient().SendAsync(request, linkedCts.Token);
var response = await HttpUtil.getHttpClient().SendAsync(request, linkedCts.Token).ConfigureAwait(false);
response.EnsureSuccessStatusCode();

return response;
Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data/Core/SFBlockingChunkDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private async Task<IResultChunk> DownloadChunkAsync(DownloadContext downloadCont
};


var httpResponse = await restRequester.GetAsync(downloadRequest, downloadContext.cancellationToken);
var httpResponse = await restRequester.GetAsync(downloadRequest, downloadContext.cancellationToken).ConfigureAwait(false);
Stream stream = Task.Run(async() => await httpResponse.Content.ReadAsStreamAsync()).Result;
IEnumerable<string> encoding;
//TODO this shouldn't be required.
Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data/Core/SFResultSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal override async Task<bool> NextAsync()
// GetNextChunk could be blocked if download result is not done yet.
// So put this piece of code in a seperate task
Logger.Info("Get next chunk from chunk downloader");
IResultChunk nextChunk = await _chunkDownloader.GetNextChunkAsync();
IResultChunk nextChunk = await _chunkDownloader.GetNextChunkAsync().ConfigureAwait(false);
if (nextChunk != null)
{
resetChunkInfo(nextChunk);
Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data/Core/SFSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ internal async Task OpenAsync(CancellationToken cancellationToken)
authenticator = new BasicAuthenticator(this);
}

await authenticator.AuthenticateAsync(cancellationToken);
await authenticator.AuthenticateAsync(cancellationToken).ConfigureAwait(false);
}

internal void close()
Expand Down
6 changes: 3 additions & 3 deletions Snowflake.Data/Core/SFStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,20 @@ internal async Task<SFBaseResultSet> ExecuteAsync(int timeout, string sql, Dicti
var queryRequest = BuildQueryRequest(sql, bindings, describeOnly);
try
{
var response = await _restRequester.PostAsync<QueryExecResponse>(queryRequest, cancellationToken);
var response = await _restRequester.PostAsync<QueryExecResponse>(queryRequest, cancellationToken).ConfigureAwait(false);
if (SessionExpired(response))
{
SfSession.renewSession();
ClearQueryRequestId();
return await ExecuteAsync(timeout, sql, bindings, describeOnly, cancellationToken);
return await ExecuteAsync(timeout, sql, bindings, describeOnly, cancellationToken).ConfigureAwait(false);
}

var lastResultUrl = response.data?.getResultUrl;

while (RequestInProgress(response) || SessionExpired(response))
{
var req = BuildResultRequest(lastResultUrl);
response = await _restRequester.GetAsync<QueryExecResponse>(req, cancellationToken);
response = await _restRequester.GetAsync<QueryExecResponse>(req, cancellationToken).ConfigureAwait(false);

if (SessionExpired(response))
{
Expand Down

0 comments on commit 0b2f1d6

Please sign in to comment.