Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Send data over cdp consecutively #12591

Merged
merged 10 commits into from
Aug 31, 2023
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 CancellationTokenSource receiveCancellationToken;
private Task receiveTask;

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
var contentBuffer = Encoding.UTF8.GetBytes(contents);

this.pendingCommands.TryAdd(message.CommandId, message);
await this.sessionSocket.SendAsync(new ArraySegment<byte>(contentBuffer), WebSocketMessageType.Text, true, cancellationToken);

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

try
{
await this.sessionSocket.SendAsync(new ArraySegment<byte>(contentBuffer), WebSocketMessageType.Text, true, cancellationToken);
}
finally
{
semaphoreSlimForSocketSend.Release();
}

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

Expand Down
Loading