File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
dotnet/src/webdriver/DevTools Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ public class DevToolsSession : IDevToolsSession
55
55
56
56
private DevToolsDomains domains ;
57
57
58
+ private readonly SemaphoreSlim semaphoreSlimForSocketSend = new SemaphoreSlim ( 1 , 1 ) ;
59
+
58
60
/// <summary>
59
61
/// Initializes a new instance of the DevToolsSession class, using the specified WebSocket endpoint.
60
62
/// </summary>
@@ -217,7 +219,18 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
217
219
218
220
string contents = JsonConvert . SerializeObject ( message ) ;
219
221
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
+ }
221
234
222
235
var responseWasReceived = await Task . Run ( ( ) => message . SyncEvent . Wait ( millisecondsTimeout . Value , cancellationToken ) ) ;
223
236
You can’t perform that action at this time.
0 commit comments