Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Hsu <kennethhsu@gmail.com>2019-05-26 23:10:15 +0300
committerKenneth Hsu <kennethhsu@gmail.com>2019-05-27 00:57:05 +0300
commitfe5e17a3fa2cc8cdf2b7453023a6a102259cc254 (patch)
treee5e3ece53435185b68db6a1b2f253a880ba198fd /Duplicati/Library/Backend/OAuthHelper
parent988c4452339b76d8e8a4964eee8364c79a90329f (diff)
Throw TimeoutException upon HTTP timeout.
The HttpClient.SendAsync method throws an OperationCanceledException when the timeout is exceeded. In order to provide a more informative exception, we will detect this case and throw a TimeoutException instead. This will also allow the BackendUploader to differentiate between cancellations requested by the user and those generated by an HTTP timeout. Previously, a ThreadAbortException or OperationCanceledException would be rethrown in the BackendUploader.DoWithRetry method. However, the modifications made in revision 61f511c087ae0e3fbb6295484a8bd9e36720f1b7 from pull request #3684 appear to have let this case slip through. See the following links for more information: https://stackoverflow.com/questions/10547895/how-can-i-tell-when-httpclient-has-timed-out https://thomaslevesque.com/2018/02/25/better-timeout-handling-with-httpclient This addresses issue #3772.
Diffstat (limited to 'Duplicati/Library/Backend/OAuthHelper')
-rw-r--r--Duplicati/Library/Backend/OAuthHelper/OAuthHttpClient.cs15
1 files changed, 13 insertions, 2 deletions
diff --git a/Duplicati/Library/Backend/OAuthHelper/OAuthHttpClient.cs b/Duplicati/Library/Backend/OAuthHelper/OAuthHttpClient.cs
index 360d5e75c..b6e48bee6 100644
--- a/Duplicati/Library/Backend/OAuthHelper/OAuthHttpClient.cs
+++ b/Duplicati/Library/Backend/OAuthHelper/OAuthHttpClient.cs
@@ -68,9 +68,20 @@ namespace Duplicati.Library
this.PreventAuthentication(request);
}
- return await this.SendAsync(request, token).ConfigureAwait(false);
+ // The HttpClient.SendAsync method throws an OperationCanceledException when the timeout is exceeded.
+ // In order to provide a more informative exception, we will detect this case and throw a TimeoutException
+ // instead. This will also allow the BackendUploader to differentiate between cancellations requested by
+ // the user and those generated by timeouts.
+ try
+ {
+ return await this.SendAsync(request, token).ConfigureAwait(false);
+ }
+ catch (OperationCanceledException ex) when (!token.IsCancellationRequested)
+ {
+ throw new TimeoutException($"HTTP timeout {this.Timeout} exceeded.");
+ }
}
-
+
/// <summary>
/// Prevents authentication from being applied on the given request
/// </summary>