Skip to content

Commit a6f37ca

Browse files
[dotnet] Send data over cdp consecutively (#12591)
* Send data over cdp consecutively * Update dotnet/src/webdriver/DevTools/DevToolsSession.cs --------- Co-authored-by: Yevgeniy Shunevych <[email protected]>
1 parent 7d5cf8f commit a6f37ca

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

dotnet/src/webdriver/DevTools/DevToolsSession.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public class DevToolsSession : IDevToolsSession
5555

5656
private DevToolsDomains domains;
5757

58+
private readonly SemaphoreSlim semaphoreSlimForSocketSend = new SemaphoreSlim(1, 1);
59+
5860
/// <summary>
5961
/// Initializes a new instance of the DevToolsSession class, using the specified WebSocket endpoint.
6062
/// </summary>
@@ -217,7 +219,18 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
217219

218220
string contents = JsonConvert.SerializeObject(message);
219221
this.pendingCommands.TryAdd(message.CommandId, message);
220-
await this.connection.SendData(contents);
222+
223+
// socket SendAsync cannot be ran simultaneously, waiting available single worker
224+
await semaphoreSlimForSocketSend.WaitAsync(cancellationToken);
225+
226+
try
227+
{
228+
await this.connection.SendData(contents);
229+
}
230+
finally
231+
{
232+
semaphoreSlimForSocketSend.Release();
233+
}
221234

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

0 commit comments

Comments
 (0)