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
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
You can’t perform that action at this time.
0 commit comments