Skip to content

Commit

Permalink
[dotnet] Send data over cdp consecutively (#12591)
Browse files Browse the repository at this point in the history
* Send data over cdp consecutively

* Update dotnet/src/webdriver/DevTools/DevToolsSession.cs

---------
Co-authored-by: Yevgeniy Shunevych <yevgeniy.shunevych@gmail.com>
  • Loading branch information
nvborisenko authored Aug 31, 2023
1 parent 7d5cf8f commit a6f37ca
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion dotnet/src/webdriver/DevTools/DevToolsSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class DevToolsSession : IDevToolsSession

private DevToolsDomains domains;

private readonly SemaphoreSlim semaphoreSlimForSocketSend = new SemaphoreSlim(1, 1);

/// <summary>
/// Initializes a new instance of the DevToolsSession class, using the specified WebSocket endpoint.
/// </summary>
Expand Down Expand Up @@ -217,7 +219,18 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains

string contents = JsonConvert.SerializeObject(message);
this.pendingCommands.TryAdd(message.CommandId, message);
await this.connection.SendData(contents);

// socket SendAsync cannot be ran simultaneously, waiting available single worker
await semaphoreSlimForSocketSend.WaitAsync(cancellationToken);

try
{
await this.connection.SendData(contents);
}
finally
{
semaphoreSlimForSocketSend.Release();
}

var responseWasReceived = await Task.Run(() => message.SyncEvent.Wait(millisecondsTimeout.Value, cancellationToken));

Expand Down

0 comments on commit a6f37ca

Please sign in to comment.