Skip to content

Commit

Permalink
Update MakeHttpRequest to use TaskFactory for async tasks
Browse files Browse the repository at this point in the history
MakeHttpRequest is an async method which is called in synchronous way
In order to avoid a deadlock (for example, when run using XUnit),
we create a new task to run the async method.

Signed-off-by: Jim Evans <[email protected]>
  • Loading branch information
macpak authored and jimevans committed Mar 17, 2020
1 parent 50749de commit c9ed1e2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion dotnet/src/webdriver/Remote/HttpCommandExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using OpenQA.Selenium.Internal;

Expand Down Expand Up @@ -145,7 +146,15 @@ public virtual Response Execute(Command commandToExecute)
HttpResponseInfo responseInfo = null;
try
{
responseInfo = this.MakeHttpRequest(requestInfo).GetAwaiter().GetResult();
// Use TaskFactory to avoid deadlock in multithreaded implementations.
responseInfo = new TaskFactory(CancellationToken.None,
TaskCreationOptions.None,
TaskContinuationOptions.None,
TaskScheduler.Default)
.StartNew(() => this.MakeHttpRequest(requestInfo))
.Unwrap()
.GetAwaiter()
.GetResult();
}
catch (HttpRequestException ex)
{
Expand Down

0 comments on commit c9ed1e2

Please sign in to comment.