Skip to content

Commit

Permalink
Hide task scheduler before calling TaskHelpers.CloseHelperAsync or Op…
Browse files Browse the repository at this point in the history
…enHelperAsync to prevent async deadlock on low/single thread sync context
  • Loading branch information
mconnew committed Aug 15, 2022
1 parent 140ed27 commit a197a75
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ public Task OpenAsync()
private async Task OpenAsync(TimeSpan timeout)
{
TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
await TaskHelpers.EnsureDefaultTaskScheduler();
if (!_useCachedFactory)
{
await GetChannelFactory().OpenHelperAsync(timeoutHelper.RemainingTime());
Expand Down Expand Up @@ -368,6 +369,7 @@ private async Task CloseAsync(TimeSpan timeout)
}

TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
await TaskHelpers.EnsureDefaultTaskScheduler();
if (_channel != null)
{
await InnerChannel.CloseHelperAsync(timeoutHelper.RemainingTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override async Task<RunSummary> RunAsync(
ConcurrentQueue<EventWrittenEventArgs> events = new ConcurrentQueue<EventWrittenEventArgs>();
s_testListener.EventWritten = events.Enqueue;
Timer timer = null;
if (_failFastDuration != System.Threading.Timeout.InfiniteTimeSpan)
if (_failFastDuration != System.Threading.Timeout.InfiniteTimeSpan && !System.Diagnostics.Debugger.IsAttached)
{
timer = new Timer((s) => Environment.FailFast("Test timed out"),
null,
Expand Down

0 comments on commit a197a75

Please sign in to comment.