@@ -15,14 +15,14 @@ namespace Microsoft.Data.SqlClient.SNI
1515 /// </summary>
1616 internal class SNISslStream : SslStream
1717 {
18- private readonly SemaphoreSlim _writeAsyncSemaphore ;
19- private readonly SemaphoreSlim _readAsyncSemaphore ;
18+ private readonly ConcurrentQueueSemaphore _writeAsyncSemaphore ;
19+ private readonly ConcurrentQueueSemaphore _readAsyncSemaphore ;
2020
2121 public SNISslStream ( Stream innerStream , bool leaveInnerStreamOpen , RemoteCertificateValidationCallback userCertificateValidationCallback )
2222 : base ( innerStream , leaveInnerStreamOpen , userCertificateValidationCallback )
2323 {
24- _writeAsyncSemaphore = new SemaphoreSlim ( 1 ) ;
25- _readAsyncSemaphore = new SemaphoreSlim ( 1 ) ;
24+ _writeAsyncSemaphore = new ConcurrentQueueSemaphore ( 1 ) ;
25+ _readAsyncSemaphore = new ConcurrentQueueSemaphore ( 1 ) ;
2626 }
2727
2828 // Prevent ReadAsync collisions by running the task in a Semaphore Slim
@@ -31,7 +31,7 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
3131 await _readAsyncSemaphore . WaitAsync ( ) . ConfigureAwait ( false ) ;
3232 try
3333 {
34- return await base . ReadAsync ( buffer , offset , count , cancellationToken ) ;
34+ return await base . ReadAsync ( buffer , offset , count , cancellationToken ) . ConfigureAwait ( false ) ;
3535 }
3636 finally
3737 {
@@ -45,7 +45,7 @@ public override async Task WriteAsync(byte[] buffer, int offset, int count, Canc
4545 await _writeAsyncSemaphore . WaitAsync ( ) . ConfigureAwait ( false ) ;
4646 try
4747 {
48- await base . WriteAsync ( buffer , offset , count , cancellationToken ) ;
48+ await base . WriteAsync ( buffer , offset , count , cancellationToken ) . ConfigureAwait ( false ) ;
4949 }
5050 finally
5151 {
@@ -59,19 +59,19 @@ public override async Task WriteAsync(byte[] buffer, int offset, int count, Canc
5959 /// </summary>
6060 internal class SNINetworkStream : NetworkStream
6161 {
62- private readonly SemaphoreSlim _writeAsyncSemaphore ;
63- private readonly SemaphoreSlim _readAsyncSemaphore ;
62+ private readonly ConcurrentQueueSemaphore _writeAsyncSemaphore ;
63+ private readonly ConcurrentQueueSemaphore _readAsyncSemaphore ;
6464
6565 public SNINetworkStream ( Socket socket , bool ownsSocket ) : base ( socket , ownsSocket )
6666 {
67- _writeAsyncSemaphore = new SemaphoreSlim ( 1 ) ;
68- _readAsyncSemaphore = new SemaphoreSlim ( 1 ) ;
67+ _writeAsyncSemaphore = new ConcurrentQueueSemaphore ( 1 ) ;
68+ _readAsyncSemaphore = new ConcurrentQueueSemaphore ( 1 ) ;
6969 }
7070
71- // Prevent the ReadAsync collisions by running the task in a Semaphore Slim
71+ // Prevent ReadAsync collisions by running the task in a Semaphore Slim
7272 public override async Task < int > ReadAsync ( byte [ ] buffer , int offset , int count , CancellationToken cancellationToken )
7373 {
74- await _readAsyncSemaphore . WaitAsync ( ) . ConfigureAwait ( false ) ;
74+ await _readAsyncSemaphore . WaitAsync ( ) ;
7575 try
7676 {
7777 return await base . ReadAsync ( buffer , offset , count , cancellationToken ) ;
@@ -85,7 +85,7 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
8585 // Prevent the WriteAsync collisions by running the task in a Semaphore Slim
8686 public override async Task WriteAsync ( byte [ ] buffer , int offset , int count , CancellationToken cancellationToken )
8787 {
88- await _writeAsyncSemaphore . WaitAsync ( ) . ConfigureAwait ( false ) ;
88+ await _writeAsyncSemaphore . WaitAsync ( ) ;
8989 try
9090 {
9191 await base . WriteAsync ( buffer , offset , count , cancellationToken ) ;
0 commit comments