@@ -271,7 +271,8 @@ void OnOpened(Amqp.IConnection connection, Open open1)
271
271
await _management . OpenAsync ( )
272
272
. ConfigureAwait ( false ) ;
273
273
274
- _nativeConnection . Closed += MaybeRecoverConnection ( ) ;
274
+ ClosedCallback closedCallback = BuildClosedCallback ( ) ;
275
+ _nativeConnection . AddClosedCallback ( closedCallback ) ;
275
276
}
276
277
catch ( AmqpException e )
277
278
{
@@ -295,7 +296,7 @@ await _management.OpenAsync()
295
296
/// and then kick off a task dedicated to recovery
296
297
/// </summary>
297
298
/// <returns></returns>
298
- private ClosedCallback MaybeRecoverConnection ( )
299
+ private ClosedCallback BuildClosedCallback ( )
299
300
{
300
301
return async ( sender , error ) =>
301
302
{
@@ -309,8 +310,7 @@ await _semaphoreClose.WaitAsync()
309
310
if ( error != null )
310
311
{
311
312
// we assume here that the connection is closed unexpectedly, since the error is not null
312
- Trace . WriteLine ( TraceLevel . Warning , $ "{ ToString ( ) } is closed unexpectedly. "
313
- ) ;
313
+ Trace . WriteLine ( TraceLevel . Warning , $ "{ ToString ( ) } closed unexpectedly.") ;
314
314
315
315
// we have to check if the recovery is active.
316
316
// The user may want to disable the recovery mechanism
@@ -327,7 +327,7 @@ await _semaphoreClose.WaitAsync()
327
327
OnNewStatus ( State . Reconnecting , Utils . ConvertError ( error ) ) ;
328
328
ChangeEntitiesStatus ( State . Reconnecting , Utils . ConvertError ( error ) ) ;
329
329
330
- await Task . Run ( async ( ) =>
330
+ Task reconnectionTask = Task . Run ( async ( ) =>
331
331
{
332
332
bool connected = false ;
333
333
// as first step we try to recover the connection
@@ -403,7 +403,10 @@ await _recordingTopologyListener.Accept(visitor)
403
403
{
404
404
Trace . WriteLine ( TraceLevel . Error , $ "{ ToString ( ) } error trying to reconnect entities { e } ") ;
405
405
}
406
- } ) . ConfigureAwait ( false ) ;
406
+ } ) ;
407
+
408
+ // TODO reconnection timeout?
409
+ await reconnectionTask . ConfigureAwait ( false ) ;
407
410
408
411
return ;
409
412
}
0 commit comments