Skip to content

Commit c9ed1e2

Browse files
macpakjimevans
authored andcommitted
Update MakeHttpRequest to use TaskFactory for async tasks
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]>
1 parent 50749de commit c9ed1e2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

dotnet/src/webdriver/Remote/HttpCommandExecutor.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using System.Net.Http;
2525
using System.Net.Http.Headers;
2626
using System.Text;
27+
using System.Threading;
2728
using System.Threading.Tasks;
2829
using OpenQA.Selenium.Internal;
2930

@@ -145,7 +146,15 @@ public virtual Response Execute(Command commandToExecute)
145146
HttpResponseInfo responseInfo = null;
146147
try
147148
{
148-
responseInfo = this.MakeHttpRequest(requestInfo).GetAwaiter().GetResult();
149+
// Use TaskFactory to avoid deadlock in multithreaded implementations.
150+
responseInfo = new TaskFactory(CancellationToken.None,
151+
TaskCreationOptions.None,
152+
TaskContinuationOptions.None,
153+
TaskScheduler.Default)
154+
.StartNew(() => this.MakeHttpRequest(requestInfo))
155+
.Unwrap()
156+
.GetAwaiter()
157+
.GetResult();
149158
}
150159
catch (HttpRequestException ex)
151160
{

0 commit comments

Comments
 (0)