@@ -306,38 +306,40 @@ private async Task SendKmsRequestAsync(KmsRequest request, CancellationToken can
306
306
307
307
var tlsStreamSettings = GetTlsStreamSettings ( request . KmsProvider ) ;
308
308
var sslStreamFactory = new SslStreamFactory ( tlsStreamSettings , _networkStreamFactory ) ;
309
- using ( var sslStream = await sslStreamFactory . CreateStreamAsync ( endpoint , cancellation ) . ConfigureAwait ( false ) )
310
- using ( var binary = request . GetMessage ( ) )
311
- {
312
- var requestBytes = binary . ToArray ( ) ;
309
+ using var sslStream = await sslStreamFactory . CreateStreamAsync ( endpoint , cancellation ) . ConfigureAwait ( false ) ;
310
+ using var binary = request . GetMessage ( ) ;
313
311
314
- var sleepMs = request . Sleep ;
315
- if ( sleepMs > 0 )
316
- {
317
- await Task . Delay ( sleepMs , cancellation ) . ConfigureAwait ( false ) ;
318
- }
312
+ var requestBytes = binary . ToArray ( ) ;
319
313
320
- await sslStream . WriteAsync ( requestBytes , 0 , requestBytes . Length ) . ConfigureAwait ( false ) ;
314
+ var sleepMs = request . Sleep ;
315
+ if ( sleepMs > 0 )
316
+ {
317
+ await Task . Delay ( sleepMs , cancellation ) . ConfigureAwait ( false ) ;
318
+ }
321
319
322
- while ( request . BytesNeeded > 0 )
323
- {
324
- var buffer = new byte [ request . BytesNeeded ] ; // BytesNeeded is the maximum number of bytes that libmongocrypt wants to receive.
325
- var count = await sslStream . ReadAsync ( buffer , 0 , buffer . Length ) . ConfigureAwait ( false ) ;
320
+ await sslStream . WriteAsync ( requestBytes , 0 , requestBytes . Length ) . ConfigureAwait ( false ) ;
326
321
327
- if ( count == 0 )
328
- {
329
- throw new IOException ( ) ;
330
- }
322
+ while ( request . BytesNeeded > 0 )
323
+ {
324
+ var buffer = new byte [ request . BytesNeeded ] ; // BytesNeeded is the maximum number of bytes that libmongocrypt wants to receive.
325
+ var count = await sslStream . ReadAsync ( buffer , 0 , buffer . Length ) . ConfigureAwait ( false ) ;
331
326
332
- var responseBytes = new byte [ count ] ;
333
- Buffer . BlockCopy ( buffer , 0 , responseBytes , 0 , count ) ;
334
- request . Feed ( responseBytes ) ;
327
+ if ( count == 0 )
328
+ {
329
+ throw new IOException ( ) ;
335
330
}
331
+
332
+ var responseBytes = new byte [ count ] ;
333
+ Buffer . BlockCopy ( buffer , 0 , responseBytes , 0 , count ) ;
334
+ request . Feed ( responseBytes ) ;
336
335
}
337
336
}
338
337
catch ( Exception ex ) when ( ex is IOException or SocketException )
339
338
{
340
- request . Fail ( ) ;
339
+ if ( ! request . Fail ( ) )
340
+ {
341
+ throw ;
342
+ }
341
343
}
342
344
}
343
345
0 commit comments