@@ -33,7 +33,6 @@ internal class InProcessResolver : Resolver
3333 private readonly Mutex _mtx ;
3434 private int _eventStreamRetryBackoff = InitialEventStreamRetryBaseBackoff ;
3535 private readonly FlagdConfig _config ;
36- private Thread _handleEventsThread ;
3736 private GrpcChannel _channel ;
3837 private Channel < object > _eventChannel ;
3938 private Model . Metadata _providerMetadata ;
@@ -66,29 +65,29 @@ public async Task Init()
6665 {
6766 await _jsonSchemaValidator . InitializeAsync ( ) . ConfigureAwait ( false ) ;
6867
69- await Task . Run ( ( ) =>
68+ var latch = new CountdownEvent ( 1 ) ;
69+ var handleEventsThread = new Thread ( async ( ) => await HandleEvents ( latch ) . ConfigureAwait ( false ) )
7070 {
71- var latch = new CountdownEvent ( 1 ) ;
72- _handleEventsThread = new Thread ( async ( ) => await HandleEvents ( latch ) . ConfigureAwait ( false ) )
73- {
74- IsBackground = true
75- } ;
76- _handleEventsThread . Start ( ) ;
77- latch . Wait ( ) ;
78- } ) . ContinueWith ( ( task ) =>
79- {
80- if ( task . IsFaulted ) throw task . Exception ;
81- } ) . ConfigureAwait ( false ) ;
71+ IsBackground = true
72+ } ;
73+ handleEventsThread . Start ( ) ;
74+ await Task . Run ( ( ) => latch . Wait ( ) ) . ConfigureAwait ( false ) ;
8275 }
8376
84- public Task Shutdown ( )
77+ public async Task Shutdown ( )
8578 {
8679 _cancellationTokenSource . Cancel ( ) ;
87- return _channel ? . ShutdownAsync ( ) . ContinueWith ( ( t ) =>
80+ try
8881 {
89- _channel . Dispose ( ) ;
90- if ( t . IsFaulted ) throw t . Exception ;
91- } ) ;
82+ if ( _channel != null )
83+ {
84+ await _channel . ShutdownAsync ( ) . ConfigureAwait ( false ) ;
85+ }
86+ }
87+ finally
88+ {
89+ _channel ? . Dispose ( ) ;
90+ }
9291 }
9392
9493 public Task < ResolutionDetails < bool > > ResolveBooleanValueAsync ( string flagKey , bool defaultValue , EvaluationContext context = null )
@@ -205,7 +204,8 @@ private T BuildClient<T>(FlagdConfig config, Func<GrpcChannel, T> constructorFun
205204 var certificate = CertificateLoader . LoadCertificate ( config . CertificatePath ) ;
206205
207206#if NET8_0_OR_GREATER
208- handler . ServerCertificateCustomValidationCallback = ( message , cert , chain , _ ) => {
207+ handler . ServerCertificateCustomValidationCallback = ( message , cert , chain , _ ) =>
208+ {
209209 // the the custom cert to the chain, Build returns a bool if valid.
210210 chain . ChainPolicy . TrustMode = X509ChainTrustMode . CustomRootTrust ;
211211 chain . ChainPolicy . CustomTrustStore . Add ( certificate ) ;
@@ -284,7 +284,8 @@ private FlagSyncService.FlagSyncServiceClient BuildClientForPlatform(FlagdConfig
284284 {
285285 var certificate = CertificateLoader . LoadCertificate ( config . CertificatePath ) ;
286286#if NET5_0_OR_GREATER
287- handler . ServerCertificateCustomValidationCallback = ( message , cert , chain , _ ) => {
287+ handler . ServerCertificateCustomValidationCallback = ( message , cert , chain , _ ) =>
288+ {
288289 // the the custom cert to the chain, Build returns a bool if valid.
289290 chain . ChainPolicy . TrustMode = X509ChainTrustMode . CustomRootTrust ;
290291 chain . ChainPolicy . CustomTrustStore . Add ( certificate ) ;
0 commit comments