@@ -66,15 +66,11 @@ private AsyncRetryPolicy<IConnection> CreateConnectionRetryPolicy(IRecoveryPolic
6666 } , ( result , _ , context ) =>
6767 {
6868 var retryCount = context . GetRetryCount ( ) ;
69- var endpoint = GetCurrentEndpoint ( context ) ;
69+ var endpoint = context . GetEndpoint ( ) ;
7070 if ( result . Exception != null )
7171 {
7272 Log . FailedToEstablishConnection ( _logger , endpoint , retryCount , result . Exception ) ;
7373 }
74- else
75- {
76- Log . ConnectionEstablished ( _logger , endpoint , retryCount ) ;
77- }
7874 } ) ;
7975 }
8076
@@ -168,11 +164,20 @@ private Task<IConnection> CreateConnection(CancellationToken cancellationToken)
168164 {
169165 var ctx = new Context ( ) ;
170166 ctx . SetRetryCount ( 0 ) ;
171- return _connectionRetryPolicy . ExecuteAsync ( ( context , ct ) =>
167+ return _connectionRetryPolicy . ExecuteAsync ( async ( context , ct ) =>
172168 {
173- var endpoint = GetCurrentEndpoint ( context ) ;
169+ int retryCount = context . GetRetryCount ( ) ;
170+ var endpoint = GetNextEndpoint ( retryCount ) ;
171+ context . SetEndpoint ( endpoint ) ;
174172 var connectionBuilder = new ConnectionBuilder ( _loggerFactory , _messageIdPolicyFactory ) ;
175- return connectionBuilder . CreateAsync ( endpoint , ct ) ;
173+ var connection = await connectionBuilder . CreateAsync ( endpoint , ct ) ;
174+
175+ if ( retryCount > 0 )
176+ {
177+ Log . ConnectionEstablished ( _logger , endpoint , retryCount ) ;
178+ }
179+
180+ return connection ;
176181 } , ctx , cancellationToken ) ;
177182 }
178183
@@ -248,9 +253,8 @@ private async Task DisposeInnerConnection()
248253 }
249254 }
250255
251- private Endpoint GetCurrentEndpoint ( Context context )
256+ private Endpoint GetNextEndpoint ( int retryCount )
252257 {
253- int retryCount = context . GetRetryCount ( ) ;
254258 return _endpoints [ retryCount % _endpoints . Length ] ;
255259 }
256260
0 commit comments