Commit 2b16da45 authored by Marc Gravell's avatar Marc Gravell

fix #934 - try to avoid exposing AggregateException unnecessarily

parent 16c50456
...@@ -566,7 +566,14 @@ internal bool TryResend(int hashSlot, Message message, EndPoint endpoint, bool i ...@@ -566,7 +566,14 @@ internal bool TryResend(int hashSlot, Message message, EndPoint endpoint, bool i
public void Wait(Task task) public void Wait(Task task)
{ {
if (task == null) throw new ArgumentNullException(nameof(task)); if (task == null) throw new ArgumentNullException(nameof(task));
if (!task.Wait(TimeoutMilliseconds)) throw new TimeoutException(); try
{
if (!task.Wait(TimeoutMilliseconds)) throw new TimeoutException();
}
catch (AggregateException aex) when (IsSingle(aex))
{
throw aex.InnerExceptions[0];
}
} }
/// <summary> /// <summary>
...@@ -577,10 +584,23 @@ public void Wait(Task task) ...@@ -577,10 +584,23 @@ public void Wait(Task task)
public T Wait<T>(Task<T> task) public T Wait<T>(Task<T> task)
{ {
if (task == null) throw new ArgumentNullException(nameof(task)); if (task == null) throw new ArgumentNullException(nameof(task));
if (!task.Wait(TimeoutMilliseconds)) throw new TimeoutException(); try
{
if (!task.Wait(TimeoutMilliseconds)) throw new TimeoutException();
}
catch (AggregateException aex) when (IsSingle(aex))
{
throw aex.InnerExceptions[0];
}
return task.Result; return task.Result;
} }
private static bool IsSingle(AggregateException aex)
{
try { return aex != null && aex.InnerExceptions.Count == 1; }
catch { return false; }
}
/// <summary> /// <summary>
/// Wait for the given asynchronous operations to complete (or timeout) /// Wait for the given asynchronous operations to complete (or timeout)
/// </summary> /// </summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment