Skip to content

Commit

Permalink
Hide task scheduler when using Task.Factory.FromAsync as can causes x…
Browse files Browse the repository at this point in the history
…unit deadlocks on low CPU core runs
  • Loading branch information
mconnew committed Aug 3, 2022
1 parent 54f8eb1 commit 3899f44
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public static Task CloseHelperAsync(this ICommunicationObject communicationObjec
}
else
{
return Task.Factory.FromAsync(communicationObject.BeginClose, communicationObject.EndClose, timeout, null);
return Task.Factory.FromAsync(communicationObject.BeginClose, communicationObject.EndClose, timeout, null, TaskCreationOptions.HideScheduler);
}
}

Expand All @@ -208,7 +208,7 @@ public static Task OpenHelperAsync(this ICommunicationObject communicationObject
}
else
{
return Task.Factory.FromAsync(communicationObject.BeginOpen, communicationObject.EndOpen, timeout, null);
return Task.Factory.FromAsync(communicationObject.BeginOpen, communicationObject.EndOpen, timeout, null, TaskCreationOptions.HideScheduler);
}
}

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 3899f44

Please sign in to comment.