diff options
author | monojenkins <jo.shields+jenkins@xamarin.com> | 2018-09-27 17:32:25 +0300 |
---|---|---|
committer | Ludovic Henry <luhenry@microsoft.com> | 2018-09-27 17:32:25 +0300 |
commit | 2cdfb380a3e69b16fd09ba64ad02d034ed6f50cc (patch) | |
tree | c9598e6acd9af45549c819d3734d1d42692c5ba1 | |
parent | aebef84fa2c88a202383e96dabb9f5693e8485b1 (diff) |
[2018-06] [System]: Make sure `HttpWebRequest` observes exceptions on timeout. #10488. (#10732)
* [System]Make sure `HttpWebRequest` observes exceptions on timeout. #10488.
`HttpWebRequest.RunWithTimeoutWorker()` needs to observe the worker task's exception
on timeout to prevent it from being thrown via the `TaskScheduler.UnobservedTaskException`
event. Fixes #10488.
* Add `TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.OnlyOnCanceled` as suggested by Marek.
* Use 'OnlyFaulted' only.
-rw-r--r-- | mcs/class/System/System.Net/HttpWebRequest.cs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/mcs/class/System/System.Net/HttpWebRequest.cs b/mcs/class/System/System.Net/HttpWebRequest.cs index 74dd1597620..9a305810d01 100644 --- a/mcs/class/System/System.Net/HttpWebRequest.cs +++ b/mcs/class/System/System.Net/HttpWebRequest.cs @@ -946,6 +946,11 @@ namespace System.Net } catch { // Ignore; we report the timeout. } +#pragma warning disable 4014 + // Make sure the workerTask's Exception is actually observed. + // Fixes https://github.com/mono/mono/issues/10488. + workerTask.ContinueWith (t => t.Exception?.GetHashCode (), TaskContinuationOptions.OnlyOnFaulted); +#pragma warning restore 4014 throw new WebException (SR.net_timeout, WebExceptionStatus.Timeout); } catch (Exception ex) { throw GetWebException (ex, aborted ()); |