@@ -11,13 +11,11 @@ namespace Ydb.Sdk;
1111public class Driver : IDisposable , IAsyncDisposable
1212{
1313 private readonly DriverConfig _config ;
14-
15- private readonly object _lock = new ( ) ;
1614 private readonly ILogger _logger ;
17-
1815 private readonly string _sdkInfo ;
1916 private readonly ChannelsCache _channels ;
20- private bool _disposed ;
17+
18+ private volatile bool _disposed ;
2119
2220 internal string Database => _config . Database ;
2321
@@ -50,15 +48,7 @@ public void Dispose()
5048
5149 private void Dispose ( bool disposing )
5250 {
53- lock ( _lock )
54- {
55- if ( _disposed )
56- {
57- return ;
58- }
59-
60- _disposed = true ;
61- }
51+ _disposed = true ;
6252
6353 if ( disposing )
6454 {
@@ -232,8 +222,7 @@ private async Task<Status> DiscoverEndpoints()
232222
233223 private async Task PeriodicDiscovery ( )
234224 {
235- var stop = false ;
236- while ( ! stop )
225+ while ( ! _disposed )
237226 {
238227 try
239228 {
@@ -248,11 +237,6 @@ private async Task PeriodicDiscovery()
248237 {
249238 _logger . LogError ( $ "Unexpected exception during session pool periodic check: { e } ") ;
250239 }
251-
252- lock ( _lock )
253- {
254- stop = _disposed ;
255- }
256240 }
257241 }
258242
@@ -268,8 +252,10 @@ private void PessimizeEndpoint(string endpoint)
268252
269253 private CallOptions GetCallOptions ( RequestSettings settings , bool streaming )
270254 {
271- var meta = new Grpc . Core . Metadata ( ) ;
272- meta . Add ( Metadata . RpcDatabaseHeader , _config . Database ) ;
255+ var meta = new Grpc . Core . Metadata
256+ {
257+ { Metadata . RpcDatabaseHeader , _config . Database }
258+ } ;
273259
274260 var authInfo = _config . Credentials . GetAuthInfo ( ) ;
275261 if ( authInfo != null )
@@ -305,19 +291,14 @@ private CallOptions GetCallOptions(RequestSettings settings, bool streaming)
305291
306292 private static StatusCode ConvertStatusCode ( Grpc . Core . StatusCode rpcStatusCode )
307293 {
308- switch ( rpcStatusCode )
294+ return rpcStatusCode switch
309295 {
310- case Grpc . Core . StatusCode . Unavailable :
311- return StatusCode . ClientTransportUnavailable ;
312- case Grpc . Core . StatusCode . DeadlineExceeded :
313- return StatusCode . ClientTransportTimeout ;
314- case Grpc . Core . StatusCode . ResourceExhausted :
315- return StatusCode . ClientTransportResourceExhausted ;
316- case Grpc . Core . StatusCode . Unimplemented :
317- return StatusCode . ClientTransportUnimplemented ;
318- default :
319- return StatusCode . ClientTransportUnknown ;
320- }
296+ Grpc . Core . StatusCode . Unavailable => StatusCode . ClientTransportUnavailable ,
297+ Grpc . Core . StatusCode . DeadlineExceeded => StatusCode . ClientTransportTimeout ,
298+ Grpc . Core . StatusCode . ResourceExhausted => StatusCode . ClientTransportResourceExhausted ,
299+ Grpc . Core . StatusCode . Unimplemented => StatusCode . ClientTransportUnimplemented ,
300+ _ => StatusCode . ClientTransportUnknown
301+ } ;
321302 }
322303
323304 private static Status ConvertStatus ( Grpc . Core . Status rpcStatus )
@@ -374,21 +355,18 @@ public async Task<bool> Next()
374355
375356 public class InitializationFailureException : Exception
376357 {
377- internal InitializationFailureException ( string message )
378- : base ( message )
358+ internal InitializationFailureException ( string message ) : base ( message )
379359 {
380360 }
381361
382- internal InitializationFailureException ( string message , Exception inner )
383- : base ( message , inner )
362+ internal InitializationFailureException ( string message , Exception inner ) : base ( message , inner )
384363 {
385364 }
386365 }
387366
388367 public class TransportException : Exception
389368 {
390- internal TransportException ( RpcException e )
391- : base ( $ "Transport exception: { e . Message } ", e )
369+ internal TransportException ( RpcException e ) : base ( $ "Transport exception: { e . Message } ", e )
392370 {
393371 Status = ConvertStatus ( e . Status ) ;
394372 }
0 commit comments