From 830b1e441c36b8179f3cf47d140264b53da2d1f7 Mon Sep 17 00:00:00 2001 From: danielmarbach Date: Tue, 17 Sep 2024 12:09:44 +0200 Subject: [PATCH 01/18] Make connection events async --- .../RabbitMQ.Client/PublicAPI.Shipped.txt | 18 +++--- .../RabbitMQ.Client/client/api/IConnection.cs | 18 +++--- .../RabbitMQ.Client/client/framing/Channel.cs | 12 ++-- .../impl/AutorecoveringConnection.Recovery.cs | 19 ++++-- .../client/impl/AutorecoveringConnection.cs | 44 ++++++------- .../client/impl/ChannelBase.cs | 19 +++--- .../client/impl/Connection.Commands.cs | 10 +-- .../client/impl/Connection.Heartbeat.cs | 3 +- .../client/impl/Connection.Receive.cs | 21 ++++--- .../RabbitMQ.Client/client/impl/Connection.cs | 62 ++++++++++--------- .../client/impl/SessionBase.cs | 7 ++- .../Test/Applications/MassPublish/Program.cs | 7 ++- projects/Test/Common/IntegrationFixture.cs | 12 +++- .../Test/Common/TestConnectionRecoveryBase.cs | 6 +- .../TestRecoveringConsumerEventHandlers.cs | 7 ++- .../TestRecoverySucceededEventHandlers.cs | 6 +- .../Connection/TestShutdownEventHandlers.cs | 6 +- .../TestConsumerRecovery.cs | 6 +- .../ConnectionRecovery/TestQueueRecovery.cs | 12 +++- .../Test/Integration/TestAsyncConsumer.cs | 8 +++ projects/Test/Integration/TestBasicPublish.cs | 1 + .../TestConnectionRecoveryWithoutSetup.cs | 25 ++++++-- .../TestConnectionTopologyRecovery.cs | 60 +++++++++++++++--- .../Test/Integration/TestFloodPublishing.cs | 4 ++ projects/Test/Integration/TestQueueDeclare.cs | 1 + projects/Test/Integration/TestToxiproxy.cs | 5 ++ projects/Test/OAuth2/TestOAuth2.cs | 3 + .../TestConnectionBlocked.cs | 6 +- .../TestConnectionBlockedChannelLeak.cs | 2 + .../TestConnectionRecovery.cs | 26 ++++++-- .../SequentialIntegration/TestHeartbeats.cs | 2 + 31 files changed, 302 insertions(+), 136 deletions(-) diff --git a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt index 87a97eb54d..99dc613f82 100644 --- a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt +++ b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt @@ -445,24 +445,24 @@ RabbitMQ.Client.IChannel.IsClosed.get -> bool RabbitMQ.Client.IChannel.IsOpen.get -> bool RabbitMQ.Client.IChannelExtensions RabbitMQ.Client.IConnection -RabbitMQ.Client.IConnection.CallbackException -> System.EventHandler +RabbitMQ.Client.IConnection.CallbackException -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.ChannelMax.get -> ushort RabbitMQ.Client.IConnection.ClientProperties.get -> System.Collections.Generic.IDictionary RabbitMQ.Client.IConnection.ClientProvidedName.get -> string RabbitMQ.Client.IConnection.CloseReason.get -> RabbitMQ.Client.ShutdownEventArgs -RabbitMQ.Client.IConnection.ConnectionBlocked -> System.EventHandler -RabbitMQ.Client.IConnection.ConnectionRecoveryError -> System.EventHandler -RabbitMQ.Client.IConnection.ConnectionShutdown -> System.EventHandler -RabbitMQ.Client.IConnection.ConnectionUnblocked -> System.EventHandler -RabbitMQ.Client.IConnection.ConsumerTagChangeAfterRecovery -> System.EventHandler +RabbitMQ.Client.IConnection.ConnectionBlocked -> RabbitMQ.Client.Events.AsyncEventHandler +RabbitMQ.Client.IConnection.ConnectionRecoveryError -> RabbitMQ.Client.Events.AsyncEventHandler +RabbitMQ.Client.IConnection.ConnectionShutdown -> RabbitMQ.Client.Events.AsyncEventHandler +RabbitMQ.Client.IConnection.ConnectionUnblocked -> RabbitMQ.Client.Events.AsyncEventHandler +RabbitMQ.Client.IConnection.ConsumerTagChangeAfterRecovery -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.Endpoint.get -> RabbitMQ.Client.AmqpTcpEndpoint RabbitMQ.Client.IConnection.FrameMax.get -> uint RabbitMQ.Client.IConnection.Heartbeat.get -> System.TimeSpan RabbitMQ.Client.IConnection.IsOpen.get -> bool RabbitMQ.Client.IConnection.Protocol.get -> RabbitMQ.Client.IProtocol -RabbitMQ.Client.IConnection.QueueNameChangedAfterRecovery -> System.EventHandler -RabbitMQ.Client.IConnection.RecoveringConsumer -> System.EventHandler -RabbitMQ.Client.IConnection.RecoverySucceeded -> System.EventHandler +RabbitMQ.Client.IConnection.QueueNameChangedAfterRecovery -> RabbitMQ.Client.Events.AsyncEventHandler +RabbitMQ.Client.IConnection.RecoveringConsumer -> RabbitMQ.Client.Events.AsyncEventHandler +RabbitMQ.Client.IConnection.RecoverySucceeded -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.ServerProperties.get -> System.Collections.Generic.IDictionary RabbitMQ.Client.IConnection.ShutdownReport.get -> System.Collections.Generic.IEnumerable RabbitMQ.Client.IConnectionExtensions diff --git a/projects/RabbitMQ.Client/client/api/IConnection.cs b/projects/RabbitMQ.Client/client/api/IConnection.cs index e28bec3c7c..ed71b171d6 100644 --- a/projects/RabbitMQ.Client/client/api/IConnection.cs +++ b/projects/RabbitMQ.Client/client/api/IConnection.cs @@ -143,9 +143,9 @@ public interface IConnection : INetworkConnection, IDisposable /// , then this event will be signalled whenever one /// of those event handlers throws an exception, as well. /// - event EventHandler CallbackException; + event AsyncEventHandler CallbackException; - event EventHandler ConnectionBlocked; + event AsyncEventHandler ConnectionBlocked; /// /// Raised when the connection is destroyed. @@ -155,7 +155,7 @@ public interface IConnection : INetworkConnection, IDisposable /// event handler is added to this event, the event handler /// will be fired immediately. /// - event EventHandler ConnectionShutdown; + event AsyncEventHandler ConnectionShutdown; /// /// Raised when the connection completes recovery. @@ -163,7 +163,7 @@ public interface IConnection : INetworkConnection, IDisposable /// /// This event will never fire for connections that disable automatic recovery. /// - event EventHandler RecoverySucceeded; + event AsyncEventHandler RecoverySucceeded; /// /// Raised when the connection recovery fails, e.g. because reconnection or topology @@ -172,7 +172,7 @@ public interface IConnection : INetworkConnection, IDisposable /// /// This event will never fire for connections that disable automatic recovery. /// - event EventHandler ConnectionRecoveryError; + event AsyncEventHandler ConnectionRecoveryError; /// /// Raised when the server-generated tag of a consumer registered on this connection changes during @@ -182,7 +182,7 @@ public interface IConnection : INetworkConnection, IDisposable /// /// This event will never fire for connections that disable automatic recovery. /// - event EventHandler ConsumerTagChangeAfterRecovery; + event AsyncEventHandler ConsumerTagChangeAfterRecovery; /// /// Raised when the name of a server-named queue declared on this connection changes during @@ -192,7 +192,7 @@ public interface IConnection : INetworkConnection, IDisposable /// /// This event will never fire for connections that disable automatic recovery. /// - event EventHandler QueueNameChangedAfterRecovery; + event AsyncEventHandler QueueNameChangedAfterRecovery; /// /// Raised when a consumer is about to be recovered. This event raises when topology recovery @@ -204,9 +204,9 @@ public interface IConnection : INetworkConnection, IDisposable /// /// This event will never fire for connections that disable automatic recovery. /// - public event EventHandler RecoveringConsumer; + public event AsyncEventHandler RecoveringConsumer; - event EventHandler ConnectionUnblocked; + event AsyncEventHandler ConnectionUnblocked; /// /// This method updates the secret used to authenticate this connection. diff --git a/projects/RabbitMQ.Client/client/framing/Channel.cs b/projects/RabbitMQ.Client/client/framing/Channel.cs index 4642f53764..b0d3cd28cc 100644 --- a/projects/RabbitMQ.Client/client/framing/Channel.cs +++ b/projects/RabbitMQ.Client/client/framing/Channel.cs @@ -117,8 +117,8 @@ protected override Task DispatchCommandAsync(IncomingCommand cmd, Cancella } case ProtocolCommandId.ConnectionBlocked: { - HandleConnectionBlocked(cmd); - return Task.FromResult(true); + // Note: always returns true + return HandleConnectionBlocked(cmd, cancellationToken); } case ProtocolCommandId.ConnectionClose: { @@ -128,7 +128,7 @@ protected override Task DispatchCommandAsync(IncomingCommand cmd, Cancella case ProtocolCommandId.ConnectionSecure: { // Note: always returns true - return HandleConnectionSecureAsync(cmd); + return HandleConnectionSecureAsync(cmd, cancellationToken); } case ProtocolCommandId.ConnectionStart: { @@ -138,12 +138,12 @@ protected override Task DispatchCommandAsync(IncomingCommand cmd, Cancella case ProtocolCommandId.ConnectionTune: { // Note: always returns true - return HandleConnectionTuneAsync(cmd); + return HandleConnectionTuneAsync(cmd, cancellationToken); } case ProtocolCommandId.ConnectionUnblocked: { - HandleConnectionUnblocked(); - return Task.FromResult(true); + // Note: always returns true + return HandleConnectionUnblocked(cancellationToken); } default: { diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs index 5d504ebf48..f4db380a9d 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs @@ -46,7 +46,7 @@ internal sealed partial class AutorecoveringConnection private Task? _recoveryTask; private readonly CancellationTokenSource _recoveryCancellationTokenSource = new CancellationTokenSource(); - private void HandleConnectionShutdown(object? _, ShutdownEventArgs args) + private Task HandleConnectionShutdown(object? _, ShutdownEventArgs args) { if (ShouldTriggerConnectionRecovery(args)) { @@ -57,6 +57,8 @@ private void HandleConnectionShutdown(object? _, ShutdownEventArgs args) } } + return Task.CompletedTask; + static bool ShouldTriggerConnectionRecovery(ShutdownEventArgs args) { if (args.Initiator == ShutdownInitiator.Peer) @@ -204,7 +206,8 @@ await RecoverChannelsAndItsConsumersAsync(recordedEntitiesSemaphoreHeld: true, c ESLog.Info("Connection recovery completed"); ThrowIfDisposed(); - _recoverySucceededWrapper.Invoke(this, EventArgs.Empty); + await _recoverySucceededWrapper.InvokeAsync(this, EventArgs.Empty) + .ConfigureAwait(false); return true; } @@ -269,7 +272,8 @@ await maybeNewInnerConnection.OpenAsync(cancellationToken) if (!_connectionRecoveryErrorWrapper.IsEmpty) { // Note: recordedEntities semaphore is _NOT_ held at this point - _connectionRecoveryErrorWrapper.Invoke(this, new ConnectionRecoveryErrorEventArgs(e)); + await _connectionRecoveryErrorWrapper.InvokeAsync(this, new ConnectionRecoveryErrorEventArgs(e)) + .ConfigureAwait(false); } maybeNewInnerConnection?.Dispose(); @@ -382,7 +386,8 @@ await RecordQueueAsync(new RecordedQueue(newName, recordedQueue), try { _recordedEntitiesSemaphore.Release(); - _queueNameChangedAfterRecoveryWrapper.Invoke(this, new QueueNameChangedAfterRecoveryEventArgs(oldName, newName)); + await _queueNameChangedAfterRecoveryWrapper.InvokeAsync(this, new QueueNameChangedAfterRecoveryEventArgs(oldName, newName)) + .ConfigureAwait(false); } finally { @@ -515,7 +520,8 @@ internal async ValueTask RecoverConsumersAsync(AutorecoveringChannel channelToRe try { _recordedEntitiesSemaphore.Release(); - _consumerAboutToBeRecovered.Invoke(this, new RecoveringConsumerEventArgs(consumer.ConsumerTag, consumer.Arguments)); + await _consumerAboutToBeRecoveredWrapper.InvokeAsync(this, new RecoveringConsumerEventArgs(consumer.ConsumerTag, consumer.Arguments)) + .ConfigureAwait(false); } finally { @@ -536,7 +542,8 @@ await _recordedEntitiesSemaphore.WaitAsync(cancellationToken) try { _recordedEntitiesSemaphore.Release(); - _consumerTagChangeAfterRecoveryWrapper.Invoke(this, new ConsumerTagChangedAfterRecoveryEventArgs(oldTag, newTag)); + await _consumerTagChangeAfterRecoveryWrapper.InvokeAsync(this, new ConsumerTagChangedAfterRecoveryEventArgs(oldTag, newTag)) + .ConfigureAwait(false); } finally { diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs index e3918e4c5a..3f68d42e42 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs @@ -67,13 +67,13 @@ internal AutorecoveringConnection(ConnectionConfig config, IEndpointResolver end _innerConnection = innerConnection; ConnectionShutdown += HandleConnectionShutdown; - _recoverySucceededWrapper = new EventingWrapper("OnConnectionRecovery", onException); - _connectionRecoveryErrorWrapper = new EventingWrapper("OnConnectionRecoveryError", onException); - _consumerTagChangeAfterRecoveryWrapper = new EventingWrapper("OnConsumerRecovery", onException); - _queueNameChangedAfterRecoveryWrapper = new EventingWrapper("OnQueueRecovery", onException); + _recoverySucceededWrapper = new AsyncEventingWrapper("OnConnectionRecovery", onExceptionAsync); + _connectionRecoveryErrorWrapper = new AsyncEventingWrapper("OnConnectionRecoveryError", onExceptionAsync); + _consumerTagChangeAfterRecoveryWrapper = new AsyncEventingWrapper("OnConsumerRecovery", onExceptionAsync); + _queueNameChangedAfterRecoveryWrapper = new AsyncEventingWrapper("OnQueueRecovery", onExceptionAsync); - void onException(Exception exception, string context) => - _innerConnection.OnCallbackException(CallbackExceptionEventArgs.Build(exception, context)); + Task onExceptionAsync(Exception exception, string context) => + _innerConnection.OnCallbackExceptionAsync(CallbackExceptionEventArgs.Build(exception, context)); } internal static async ValueTask CreateAsync(ConnectionConfig config, IEndpointResolver endpoints, @@ -88,64 +88,64 @@ await innerConnection.OpenAsync(cancellationToken) return connection; } - public event EventHandler RecoverySucceeded + public event AsyncEventHandler RecoverySucceeded { add => _recoverySucceededWrapper.AddHandler(value); remove => _recoverySucceededWrapper.RemoveHandler(value); } - private EventingWrapper _recoverySucceededWrapper; + private AsyncEventingWrapper _recoverySucceededWrapper; - public event EventHandler ConnectionRecoveryError + public event AsyncEventHandler ConnectionRecoveryError { add => _connectionRecoveryErrorWrapper.AddHandler(value); remove => _connectionRecoveryErrorWrapper.RemoveHandler(value); } - private EventingWrapper _connectionRecoveryErrorWrapper; + private AsyncEventingWrapper _connectionRecoveryErrorWrapper; - public event EventHandler CallbackException + public event AsyncEventHandler CallbackException { add => InnerConnection.CallbackException += value; remove => InnerConnection.CallbackException -= value; } - public event EventHandler ConnectionBlocked + public event AsyncEventHandler ConnectionBlocked { add => InnerConnection.ConnectionBlocked += value; remove => InnerConnection.ConnectionBlocked -= value; } - public event EventHandler ConnectionShutdown + public event AsyncEventHandler ConnectionShutdown { add => InnerConnection.ConnectionShutdown += value; remove => InnerConnection.ConnectionShutdown -= value; } - public event EventHandler ConnectionUnblocked + public event AsyncEventHandler ConnectionUnblocked { add => InnerConnection.ConnectionUnblocked += value; remove => InnerConnection.ConnectionUnblocked -= value; } - public event EventHandler ConsumerTagChangeAfterRecovery + public event AsyncEventHandler ConsumerTagChangeAfterRecovery { add => _consumerTagChangeAfterRecoveryWrapper.AddHandler(value); remove => _consumerTagChangeAfterRecoveryWrapper.RemoveHandler(value); } - private EventingWrapper _consumerTagChangeAfterRecoveryWrapper; + private AsyncEventingWrapper _consumerTagChangeAfterRecoveryWrapper; - public event EventHandler QueueNameChangedAfterRecovery + public event AsyncEventHandler QueueNameChangedAfterRecovery { add => _queueNameChangedAfterRecoveryWrapper.AddHandler(value); remove => _queueNameChangedAfterRecoveryWrapper.RemoveHandler(value); } - private EventingWrapper _queueNameChangedAfterRecoveryWrapper; + private AsyncEventingWrapper _queueNameChangedAfterRecoveryWrapper; - public event EventHandler RecoveringConsumer + public event AsyncEventHandler RecoveringConsumer { - add => _consumerAboutToBeRecovered.AddHandler(value); - remove => _consumerAboutToBeRecovered.RemoveHandler(value); + add => _consumerAboutToBeRecoveredWrapper.AddHandler(value); + remove => _consumerAboutToBeRecoveredWrapper.RemoveHandler(value); } - private EventingWrapper _consumerAboutToBeRecovered; + private AsyncEventingWrapper _consumerAboutToBeRecoveredWrapper; public string? ClientProvidedName => _config.ClientProvidedName; diff --git a/projects/RabbitMQ.Client/client/impl/ChannelBase.cs b/projects/RabbitMQ.Client/client/impl/ChannelBase.cs index 225ba95541..0743cc9351 100644 --- a/projects/RabbitMQ.Client/client/impl/ChannelBase.cs +++ b/projects/RabbitMQ.Client/client/impl/ChannelBase.cs @@ -701,10 +701,12 @@ await ModelSendAsync(method, cancellationToken). return true; } - protected void HandleConnectionBlocked(IncomingCommand cmd) + protected async Task HandleConnectionBlocked(IncomingCommand cmd, CancellationToken cancellationToken) { string reason = new ConnectionBlocked(cmd.MethodSpan)._reason; - Session.Connection.HandleConnectionBlocked(reason); + await Session.Connection.HandleConnectionBlocked(reason) + .ConfigureAwait(false); + return true; } protected async Task HandleConnectionCloseAsync(IncomingCommand cmd, CancellationToken cancellationToken) @@ -713,7 +715,8 @@ protected async Task HandleConnectionCloseAsync(IncomingCommand cmd, Cance var reason = new ShutdownEventArgs(ShutdownInitiator.Peer, method._replyCode, method._replyText, method._classId, method._methodId); try { - Session.Connection.ClosedViaPeer(reason); + await Session.Connection.ClosedViaPeer(reason) + .ConfigureAwait(false); var replyMethod = new ConnectionCloseOk(); await ModelSendAsync(replyMethod, cancellationToken) @@ -735,7 +738,7 @@ await ModelSendAsync(replyMethod, cancellationToken) return true; } - protected async Task HandleConnectionSecureAsync(IncomingCommand _) + protected async Task HandleConnectionSecureAsync(IncomingCommand cmd, CancellationToken cancellationToken) { var k = (ConnectionSecureOrTuneAsyncRpcContinuation)_continuationQueue.Next(); await k.HandleCommandAsync(new IncomingCommand()) @@ -765,7 +768,7 @@ await Session.Connection.CloseAsync(reason, false, return true; } - protected async Task HandleConnectionTuneAsync(IncomingCommand cmd) + protected async Task HandleConnectionTuneAsync(IncomingCommand cmd, CancellationToken cancellationToken) { // Note: `using` here to ensure instance is disposed using var k = (ConnectionSecureOrTuneAsyncRpcContinuation)_continuationQueue.Next(); @@ -777,9 +780,11 @@ await k.HandleCommandAsync(cmd) return true; } - protected void HandleConnectionUnblocked() + protected async Task HandleConnectionUnblocked(CancellationToken cancellationToken) { - Session.Connection.HandleConnectionUnblocked(); + await Session.Connection.HandleConnectionUnblocked() + .ConfigureAwait(false); + return true; } public async ValueTask GetNextPublishSequenceNumberAsync(CancellationToken cancellationToken = default) diff --git a/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs b/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs index 2cdc180df2..fc3e05761a 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs @@ -54,20 +54,22 @@ internal void NotifyReceivedCloseOk() _closed = true; } - internal void HandleConnectionBlocked(string reason) + internal Task HandleConnectionBlocked(string reason) { if (!_connectionBlockedWrapper.IsEmpty) { - _connectionBlockedWrapper.Invoke(this, new ConnectionBlockedEventArgs(reason)); + return _connectionBlockedWrapper.InvokeAsync(this, new ConnectionBlockedEventArgs(reason)); } + return Task.CompletedTask; } - internal void HandleConnectionUnblocked() + internal Task HandleConnectionUnblocked() { if (!_connectionUnblockedWrapper.IsEmpty) { - _connectionUnblockedWrapper.Invoke(this, EventArgs.Empty); + return _connectionUnblockedWrapper.InvokeAsync(this, EventArgs.Empty); } + return Task.CompletedTask; } private async ValueTask StartAndTuneAsync(CancellationToken cancellationToken) diff --git a/projects/RabbitMQ.Client/client/impl/Connection.Heartbeat.cs b/projects/RabbitMQ.Client/client/impl/Connection.Heartbeat.cs index e5588d39cd..56aec1897f 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.Heartbeat.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.Heartbeat.cs @@ -108,7 +108,8 @@ private async void HeartbeatReadTimerCallback(object? state) { var eose = new EndOfStreamException($"Heartbeat missing with heartbeat == {_heartbeat} seconds"); LogCloseError(eose.Message, eose); - HandleMainLoopException(new ShutdownEventArgs(ShutdownInitiator.Library, 0, "End of stream", eose)); + await HandleMainLoopException(new ShutdownEventArgs(ShutdownInitiator.Library, 0, "End of stream", eose)) + .ConfigureAwait(false); shouldTerminate = true; } } diff --git a/projects/RabbitMQ.Client/client/impl/Connection.Receive.cs b/projects/RabbitMQ.Client/client/impl/Connection.Receive.cs index c3a90f8ec4..8e69e84949 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.Receive.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.Receive.cs @@ -62,7 +62,8 @@ await ReceiveLoopAsync(mainLoopToken) Constants.InternalError, "Thread aborted (AppDomain unloaded?)", exception: taex); - HandleMainLoopException(ea); + await HandleMainLoopException(ea) + .ConfigureAwait(false); } #endif catch (EndOfStreamException eose) @@ -72,7 +73,8 @@ await ReceiveLoopAsync(mainLoopToken) 0, "End of stream", exception: eose); - HandleMainLoopException(ea); + await HandleMainLoopException(ea) + .ConfigureAwait(false); } catch (HardProtocolException hpe) { @@ -89,7 +91,8 @@ await HardProtocolExceptionHandlerAsync(hpe, mainLoopToken) Constants.InternalError, fileLoadException.Message, exception: fileLoadException); - HandleMainLoopException(ea); + await HandleMainLoopException(ea) + .ConfigureAwait(false); } catch (OperationCanceledException ocex) { @@ -103,7 +106,8 @@ await HardProtocolExceptionHandlerAsync(hpe, mainLoopToken) Constants.InternalError, ocex.Message, exception: ocex); - HandleMainLoopException(ea); + await HandleMainLoopException(ea) + .ConfigureAwait(false); } } catch (Exception ex) @@ -112,7 +116,8 @@ await HardProtocolExceptionHandlerAsync(hpe, mainLoopToken) Constants.InternalError, ex.Message, exception: ex); - HandleMainLoopException(ea); + await HandleMainLoopException(ea) + .ConfigureAwait(false); } using var cts = new CancellationTokenSource(InternalConstants.DefaultConnectionCloseTimeout); @@ -202,7 +207,7 @@ private void MaybeTerminateMainloopAndStopHeartbeatTimers(bool cancelMainLoop = MaybeStopHeartbeatTimers(); } - private void HandleMainLoopException(ShutdownEventArgs reason) + private async Task HandleMainLoopException(ShutdownEventArgs reason) { string message = reason.GetLogMessage(); if (false == SetCloseReason(reason)) @@ -213,7 +218,7 @@ private void HandleMainLoopException(ShutdownEventArgs reason) _channel0.MaybeSetConnectionStartException(reason.Exception!); - OnShutdown(reason); + await OnShutdown(reason).ConfigureAwait(false); LogCloseError($"unexpected connection closure: {message}", reason.Exception!); } @@ -222,7 +227,7 @@ private async Task HardProtocolExceptionHandlerAsync(HardProtocolException hpe, { if (SetCloseReason(hpe.ShutdownReason)) { - OnShutdown(hpe.ShutdownReason); + await OnShutdown(hpe.ShutdownReason).ConfigureAwait(false); await _session0.SetSessionClosingAsync(false) .ConfigureAwait(false); try diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index 8e8065b8d6..eac78e104b 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -64,11 +64,11 @@ internal Connection(ConnectionConfig config, IFrameHandler frameHandler) _config = config; _frameHandler = frameHandler; - Action onException = (exception, context) => OnCallbackException(CallbackExceptionEventArgs.Build(exception, context)); - _callbackExceptionWrapper = new EventingWrapper(string.Empty, (exception, context) => { }); - _connectionBlockedWrapper = new EventingWrapper("OnConnectionBlocked", onException); - _connectionUnblockedWrapper = new EventingWrapper("OnConnectionUnblocked", onException); - _connectionShutdownWrapper = new EventingWrapper("OnShutdown", onException); + Func onException = (exception, context) => OnCallbackExceptionAsync(CallbackExceptionEventArgs.Build(exception, context)); + _callbackExceptionWrapper = new AsyncEventingWrapper(string.Empty, (exception, context) => Task.CompletedTask); + _connectionBlockedWrapper = new AsyncEventingWrapper("OnConnectionBlocked", onException); + _connectionUnblockedWrapper = new AsyncEventingWrapper("OnConnectionUnblocked", onException); + _connectionShutdownWrapper = new AsyncEventingWrapper("OnShutdown", onException); _sessionManager = new SessionManager(this, 0, config.MaxInboundMessageBodySize); _session0 = new MainSession(this, config.MaxInboundMessageBodySize); @@ -118,35 +118,35 @@ internal IFrameHandler FrameHandler get { return _frameHandler; } } - public event EventHandler CallbackException + public event AsyncEventHandler CallbackException { add => _callbackExceptionWrapper.AddHandler(value); remove => _callbackExceptionWrapper.RemoveHandler(value); } - private EventingWrapper _callbackExceptionWrapper; + private AsyncEventingWrapper _callbackExceptionWrapper; - public event EventHandler ConnectionBlocked + public event AsyncEventHandler ConnectionBlocked { add => _connectionBlockedWrapper.AddHandler(value); remove => _connectionBlockedWrapper.RemoveHandler(value); } - private EventingWrapper _connectionBlockedWrapper; + private AsyncEventingWrapper _connectionBlockedWrapper; - public event EventHandler ConnectionUnblocked + public event AsyncEventHandler ConnectionUnblocked { add => _connectionUnblockedWrapper.AddHandler(value); remove => _connectionUnblockedWrapper.RemoveHandler(value); } - private EventingWrapper _connectionUnblockedWrapper; + private AsyncEventingWrapper _connectionUnblockedWrapper; - public event EventHandler RecoveringConsumer + public event AsyncEventHandler RecoveringConsumer { - add => _consumerAboutToBeRecovered.AddHandler(value); - remove => _consumerAboutToBeRecovered.RemoveHandler(value); + add => _consumerAboutToBeRecoveredWrapper.AddHandler(value); + remove => _consumerAboutToBeRecoveredWrapper.RemoveHandler(value); } - private EventingWrapper _consumerAboutToBeRecovered; + private AsyncEventingWrapper _consumerAboutToBeRecoveredWrapper; - public event EventHandler ConnectionShutdown + public event AsyncEventHandler ConnectionShutdown { add { @@ -167,12 +167,12 @@ public event EventHandler ConnectionShutdown _connectionShutdownWrapper.RemoveHandler(value); } } - private EventingWrapper _connectionShutdownWrapper; + private AsyncEventingWrapper _connectionShutdownWrapper; /// /// This event is never fired by non-recovering connections but it is a part of the interface. /// - public event EventHandler RecoverySucceeded + public event AsyncEventHandler RecoverySucceeded { add { } remove { } @@ -181,7 +181,7 @@ public event EventHandler RecoverySucceeded /// /// This event is never fired by non-recovering connections but it is a part of the interface. /// - public event EventHandler ConnectionRecoveryError + public event AsyncEventHandler ConnectionRecoveryError { add { } remove { } @@ -190,7 +190,7 @@ public event EventHandler ConnectionRecoveryEr /// /// This event is never fired by non-recovering connections but it is a part of the interface. /// - public event EventHandler ConsumerTagChangeAfterRecovery + public event AsyncEventHandler ConsumerTagChangeAfterRecovery { add { } remove { } @@ -199,7 +199,7 @@ public event EventHandler ConsumerTagC /// /// This event is never fired by non-recovering connections but it is a part of the interface. /// - public event EventHandler QueueNameChangedAfterRecovery + public event AsyncEventHandler QueueNameChangedAfterRecovery { add { } remove { } @@ -211,6 +211,7 @@ internal void TakeOver(Connection other) _connectionBlockedWrapper.Takeover(other._connectionBlockedWrapper); _connectionUnblockedWrapper.Takeover(other._connectionUnblockedWrapper); _connectionShutdownWrapper.Takeover(other._connectionShutdownWrapper); + // TODO Why are other wrappers not taken over? } internal async ValueTask OpenAsync(CancellationToken cancellationToken) @@ -319,7 +320,8 @@ internal async Task CloseAsync(ShutdownEventArgs reason, bool abort, TimeSpan ti { cancellationToken.ThrowIfCancellationRequested(); - OnShutdown(reason); + await OnShutdown(reason) + .ConfigureAwait(false); await _session0.SetSessionClosingAsync(false) .ConfigureAwait(false); @@ -399,7 +401,7 @@ await _frameHandler.CloseAsync(cancellationToken) } } - internal void ClosedViaPeer(ShutdownEventArgs reason) + internal async Task ClosedViaPeer(ShutdownEventArgs reason) { if (false == SetCloseReason(reason)) { @@ -410,8 +412,10 @@ internal void ClosedViaPeer(ShutdownEventArgs reason) // We are quiescing, but still allow for server-close } - OnShutdown(reason); - _session0.SetSessionClosing(true); + await OnShutdown(reason) + .ConfigureAwait(false); + await _session0.SetSessionClosingAsync(true) + .ConfigureAwait(false); MaybeTerminateMainloopAndStopHeartbeatTimers(cancelMainLoop: true); } @@ -429,10 +433,10 @@ private async Task FinishCloseAsync(CancellationToken cancellationToken) } ///Broadcasts notification of the final shutdown of the connection. - private void OnShutdown(ShutdownEventArgs reason) + private Task OnShutdown(ShutdownEventArgs reason) { ThrowIfDisposed(); - _connectionShutdownWrapper.Invoke(this, reason); + return _connectionShutdownWrapper.InvokeAsync(this, reason); } private bool SetCloseReason(ShutdownEventArgs reason) @@ -458,9 +462,9 @@ private void LogCloseError(string error, Exception ex) } } - internal void OnCallbackException(CallbackExceptionEventArgs args) + internal Task OnCallbackExceptionAsync(CallbackExceptionEventArgs args) { - _callbackExceptionWrapper.Invoke(this, args); + return _callbackExceptionWrapper.InvokeAsync(this, args); } internal ValueTask WriteAsync(RentedMemory frames, CancellationToken cancellationToken) diff --git a/projects/RabbitMQ.Client/client/impl/SessionBase.cs b/projects/RabbitMQ.Client/client/impl/SessionBase.cs index b5dea9b14a..5f8a0b63c1 100644 --- a/projects/RabbitMQ.Client/client/impl/SessionBase.cs +++ b/projects/RabbitMQ.Client/client/impl/SessionBase.cs @@ -53,7 +53,7 @@ protected SessionBase(Connection connection, ushort channelNumber) ChannelNumber = channelNumber; if (channelNumber != 0) { - connection.ConnectionShutdown += OnConnectionShutdown; + connection.ConnectionShutdown += OnConnectionShutdownAsync; } RabbitMqClientEventSource.Log.ChannelOpened(); } @@ -86,14 +86,15 @@ public event EventHandler SessionShutdown [MemberNotNullWhen(false, nameof(CloseReason))] public bool IsOpen => CloseReason is null; - public virtual void OnConnectionShutdown(object? conn, ShutdownEventArgs reason) + public virtual Task OnConnectionShutdownAsync(object? conn, ShutdownEventArgs reason) { Close(reason); + return Task.CompletedTask; } public virtual void OnSessionShutdown(ShutdownEventArgs reason) { - Connection.ConnectionShutdown -= OnConnectionShutdown; + Connection.ConnectionShutdown -= OnConnectionShutdownAsync; _sessionShutdownWrapper.Invoke(this, reason); } diff --git a/projects/Test/Applications/MassPublish/Program.cs b/projects/Test/Applications/MassPublish/Program.cs index b0785c0fac..7d06b48956 100644 --- a/projects/Test/Applications/MassPublish/Program.cs +++ b/projects/Test/Applications/MassPublish/Program.cs @@ -68,7 +68,7 @@ static Program() static async Task Main() { using IConnection consumeConnection = await s_consumeConnectionFactory.CreateConnectionAsync(); - consumeConnection.ConnectionShutdown += Connection_ConnectionShutdown; + consumeConnection.ConnectionShutdown += ConnectionConnectionShutdown; using IChannel consumeChannel = await consumeConnection.CreateChannelAsync(); consumeChannel.ChannelShutdown += Channel_ChannelShutdown; @@ -92,7 +92,7 @@ await consumeChannel.BasicConsumeAsync(queue: QueueName, autoAck: true, consumer for (int i = 0; i < ConnectionCount; i++) { IConnection publishConnection = await s_publishConnectionFactory.CreateConnectionAsync($"{AppId}-PUBLISH-{i}"); - publishConnection.ConnectionShutdown += Connection_ConnectionShutdown; + publishConnection.ConnectionShutdown += ConnectionConnectionShutdown; publishConnections.Add(publishConnection); } @@ -163,13 +163,14 @@ private static void PublishChannel_BasicNacks(object sender, BasicNackEventArgs Console.Error.WriteLine("[ERROR] unexpected nack on publish: {0}", e); } - private static void Connection_ConnectionShutdown(object sender, ShutdownEventArgs e) + private static Task ConnectionConnectionShutdown(object sender, ShutdownEventArgs e) { if (e.Initiator != ShutdownInitiator.Application) { Console.Error.WriteLine("[ERROR] unexpected connection shutdown: {0}", e); s_consumeDoneEvent.TrySetResult(false); } + return Task.CompletedTask; } private static void Channel_ChannelShutdown(object sender, ShutdownEventArgs e) diff --git a/projects/Test/Common/IntegrationFixture.cs b/projects/Test/Common/IntegrationFixture.cs index ea447bdb5f..1de939280a 100644 --- a/projects/Test/Common/IntegrationFixture.cs +++ b/projects/Test/Common/IntegrationFixture.cs @@ -237,6 +237,7 @@ protected void AddCallbackExceptionHandlers(IConnection conn, IChannel channel) catch (InvalidOperationException) { } + return Task.CompletedTask; }; conn.CallbackException += (o, ea) => @@ -251,6 +252,7 @@ protected void AddCallbackExceptionHandlers(IConnection conn, IChannel channel) catch (InvalidOperationException) { } + return Task.CompletedTask; }; } @@ -289,6 +291,7 @@ protected void AddCallbackShutdownHandlers() { } }); + return Task.CompletedTask; }; } @@ -528,13 +531,14 @@ protected ConnectionFactory CreateConnectionFactory( }; } - protected void HandleConnectionShutdown(object sender, ShutdownEventArgs args) + protected Task HandleConnectionShutdown(object sender, ShutdownEventArgs args) { if (args.Initiator != ShutdownInitiator.Application) { IConnection conn = (IConnection)sender; _output.WriteLine($"{_testDisplayName} connection {conn.ClientProvidedName} shut down: {args}"); } + return Task.CompletedTask; } protected void HandleConnectionShutdown(IConnection conn, ShutdownEventArgs args, Action a) @@ -625,7 +629,11 @@ protected static TaskCompletionSource PrepareForRecovery(IConnection conn) var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); AutorecoveringConnection aconn = conn as AutorecoveringConnection; - aconn.RecoverySucceeded += (source, ea) => tcs.TrySetResult(true); + aconn.RecoverySucceeded += (source, ea) => + { + tcs.TrySetResult(true); + return Task.CompletedTask; + }; return tcs; } diff --git a/projects/Test/Common/TestConnectionRecoveryBase.cs b/projects/Test/Common/TestConnectionRecoveryBase.cs index de581f0c40..a10403f9ee 100644 --- a/projects/Test/Common/TestConnectionRecoveryBase.cs +++ b/projects/Test/Common/TestConnectionRecoveryBase.cs @@ -229,7 +229,11 @@ protected static TaskCompletionSource PrepareForShutdown(IConnection conn) var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); AutorecoveringConnection aconn = conn as AutorecoveringConnection; - aconn.ConnectionShutdown += (c, args) => tcs.TrySetResult(true); + aconn.ConnectionShutdown += (c, args) => + { + tcs.TrySetResult(true); + return Task.CompletedTask; + }; return tcs; } diff --git a/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoveringConsumerEventHandlers.cs b/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoveringConsumerEventHandlers.cs index 0ab41bc124..919b1c35b2 100644 --- a/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoveringConsumerEventHandlers.cs +++ b/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoveringConsumerEventHandlers.cs @@ -56,7 +56,11 @@ public async Task TestRecoveringConsumerEventHandlers_Called(int iterations) await _channel.BasicConsumeAsync(q, true, cons); int counter = 0; - ((AutorecoveringConnection)_conn).RecoveringConsumer += (sender, args) => Interlocked.Increment(ref counter); + ((AutorecoveringConnection)_conn).RecoveringConsumer += (sender, args) => + { + Interlocked.Increment(ref counter); + return Task.CompletedTask; + }; for (int i = 0; i < iterations; i++) { @@ -91,6 +95,7 @@ public async Task TestRecoveringConsumerEventHandler_EventArgumentsArePassedDown // and assert in the test function. ctagMatches = args.ConsumerTag == expectedCTag; consumerArgumentMatches = (string)args.ConsumerArguments[key] == value; + return Task.CompletedTask; }; await CloseAndWaitForRecoveryAsync(); diff --git a/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoverySucceededEventHandlers.cs b/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoverySucceededEventHandlers.cs index ef7ba04cea..4bd514c694 100644 --- a/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoverySucceededEventHandlers.cs +++ b/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoverySucceededEventHandlers.cs @@ -47,7 +47,11 @@ public TestRecoverySucceededEventHandlers(ITestOutputHelper output) : base(outpu public async Task TestRecoverySucceededEventHandlers_Called() { int counter = 0; - ((AutorecoveringConnection)_conn).RecoverySucceeded += (source, ea) => Interlocked.Increment(ref counter); + ((AutorecoveringConnection)_conn).RecoverySucceeded += (source, ea) => + { + Interlocked.Increment(ref counter); + return Task.CompletedTask; + }; await CloseAndWaitForRecoveryAsync(); await CloseAndWaitForRecoveryAsync(); diff --git a/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestShutdownEventHandlers.cs b/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestShutdownEventHandlers.cs index 03d5ad34b9..a189edc5dc 100644 --- a/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestShutdownEventHandlers.cs +++ b/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestShutdownEventHandlers.cs @@ -46,7 +46,11 @@ public TestShutdownEventHandlers(ITestOutputHelper output) : base(output) public async Task TestShutdownEventHandlers_Called() { int counter = 0; - _conn.ConnectionShutdown += (c, args) => Interlocked.Increment(ref counter); + _conn.ConnectionShutdown += (c, args) => + { + Interlocked.Increment(ref counter); + return Task.CompletedTask; + }; Assert.True(_conn.IsOpen); await CloseAndWaitForRecoveryAsync(); diff --git a/projects/Test/Integration/ConnectionRecovery/TestConsumerRecovery.cs b/projects/Test/Integration/ConnectionRecovery/TestConsumerRecovery.cs index da4c465561..aa79ce6e3b 100644 --- a/projects/Test/Integration/ConnectionRecovery/TestConsumerRecovery.cs +++ b/projects/Test/Integration/ConnectionRecovery/TestConsumerRecovery.cs @@ -58,7 +58,11 @@ public async Task TestConsumerRecoveryWithManyConsumers() } var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - ((AutorecoveringConnection)_conn).ConsumerTagChangeAfterRecovery += (prev, current) => tcs.TrySetResult(true); + ((AutorecoveringConnection)_conn).ConsumerTagChangeAfterRecovery += (prev, current) => + { + tcs.TrySetResult(true); + return Task.CompletedTask; + }; await CloseAndWaitForRecoveryAsync(); await WaitAsync(tcs, "consumer tag change after recovery"); diff --git a/projects/Test/Integration/ConnectionRecovery/TestQueueRecovery.cs b/projects/Test/Integration/ConnectionRecovery/TestQueueRecovery.cs index a759611630..cd29505d55 100644 --- a/projects/Test/Integration/ConnectionRecovery/TestQueueRecovery.cs +++ b/projects/Test/Integration/ConnectionRecovery/TestQueueRecovery.cs @@ -76,8 +76,16 @@ public async Task TestServerNamedQueueRecovery() var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var connection = (AutorecoveringConnection)_conn; - connection.RecoverySucceeded += (source, ea) => tcs.SetResult(true); - connection.QueueNameChangedAfterRecovery += (source, ea) => { nameAfter = ea.NameAfter; }; + connection.RecoverySucceeded += (source, ea) => + { + tcs.SetResult(true); + return Task.CompletedTask; + }; + connection.QueueNameChangedAfterRecovery += (source, ea) => + { + nameAfter = ea.NameAfter; + return Task.CompletedTask; + }; await CloseAndWaitForRecoveryAsync(); await WaitAsync(tcs, "recovery succeeded"); diff --git a/projects/Test/Integration/TestAsyncConsumer.cs b/projects/Test/Integration/TestAsyncConsumer.cs index 2edda15c7a..4e1e37cf0c 100644 --- a/projects/Test/Integration/TestAsyncConsumer.cs +++ b/projects/Test/Integration/TestAsyncConsumer.cs @@ -93,6 +93,7 @@ public async Task TestBasicRoundtripConcurrent() { MaybeSetException(args, publish1SyncSource, publish2SyncSource); }); + return Task.CompletedTask; }; _channel.ChannelShutdown += (o, ea) => @@ -185,6 +186,7 @@ public async Task TestBasicRoundtripConcurrentManyMessages() { MaybeSetException(args, publish1SyncSource, publish2SyncSource); }); + return Task.CompletedTask; }; _channel.ChannelShutdown += (o, ea) => @@ -208,6 +210,7 @@ public async Task TestBasicRoundtripConcurrentManyMessages() { MaybeSetException(args, publish1SyncSource, publish2SyncSource); }); + return Task.CompletedTask; }; using (IChannel publishChannel = await publishConn.CreateChannelAsync()) { @@ -251,6 +254,7 @@ public async Task TestBasicRoundtripConcurrentManyMessages() { MaybeSetException(ea, publish1SyncSource, publish2SyncSource); }); + return Task.CompletedTask; }; using (IChannel consumeChannel = await consumeConn.CreateChannelAsync()) { @@ -349,6 +353,7 @@ public async Task TestBasicRejectAsync() { MaybeSetException(args, publishSyncSource); }); + return Task.CompletedTask; }; _channel.ChannelShutdown += (o, ea) => @@ -445,6 +450,7 @@ public async Task TestBasicAckAsync() { MaybeSetException(args, publishSyncSource); }); + return Task.CompletedTask; }; _channel.ChannelShutdown += (o, ea) => @@ -509,6 +515,7 @@ public async Task TestBasicNackAsync() { MaybeSetException(ea, publishSyncSource); }); + return Task.CompletedTask; }; _channel.ChannelShutdown += (o, ea) => @@ -615,6 +622,7 @@ public async Task TestCreateChannelWithinAsyncConsumerCallback_GH650() { MaybeSetException(ea, tcs); }); + return Task.CompletedTask; }; _channel.ChannelShutdown += (o, ea) => diff --git a/projects/Test/Integration/TestBasicPublish.cs b/projects/Test/Integration/TestBasicPublish.cs index c4266bc3df..379e2bfa07 100644 --- a/projects/Test/Integration/TestBasicPublish.cs +++ b/projects/Test/Integration/TestBasicPublish.cs @@ -205,6 +205,7 @@ public async Task TestMaxInboundMessageBodySize() conn.ConnectionShutdown += (o, a) => { sawConnectionShutdown = true; + return Task.CompletedTask; }; Assert.Equal(maxMsgSize, cf.MaxInboundMessageBodySize); diff --git a/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs b/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs index c13d66ee42..235845795d 100644 --- a/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs +++ b/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs @@ -167,7 +167,11 @@ public async Task TestConsumerRecoveryOnClientNamedQueueWithOneRecovery() await AssertConsumerCountAsync(ch, q1, 1); bool queueNameChangeAfterRecoveryCalled = false; - c.QueueNameChangedAfterRecovery += (source, ea) => { queueNameChangeAfterRecoveryCalled = true; }; + c.QueueNameChangedAfterRecovery += (source, ea) => + { + queueNameChangeAfterRecoveryCalled = true; + return Task.CompletedTask; + }; // connection #2 await CloseAndWaitForRecoveryAsync(c); @@ -227,6 +231,7 @@ public async Task TestConsumerRecoveryWithServerNamedQueue() queueNameChangeAfterRecoveryCalled = true; queueNameBeforeIsEqual = qname.Equals(ea.NameBefore); qnameAfterRecovery = ea.NameAfter; + return Task.CompletedTask; }; await CloseAndWaitForRecoveryAsync(c); @@ -285,9 +290,21 @@ public async Task TestTopologyRecoveryConsumerFilter() using (AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryFilterAsync(filter)) { - conn.RecoverySucceeded += (source, ea) => connectionRecoveryTcs.SetResult(true); - conn.ConnectionRecoveryError += (source, ea) => connectionRecoveryTcs.SetException(ea.Exception); - conn.CallbackException += (source, ea) => connectionRecoveryTcs.SetException(ea.Exception); + conn.RecoverySucceeded += (source, ea) => + { + connectionRecoveryTcs.SetResult(true); + return Task.CompletedTask; + }; + conn.ConnectionRecoveryError += (source, ea) => + { + connectionRecoveryTcs.SetException(ea.Exception); + return Task.CompletedTask; + }; + conn.CallbackException += (source, ea) => + { + connectionRecoveryTcs.SetException(ea.Exception); + return Task.CompletedTask; + }; using (IChannel ch = await conn.CreateChannelAsync()) { diff --git a/projects/Test/Integration/TestConnectionTopologyRecovery.cs b/projects/Test/Integration/TestConnectionTopologyRecovery.cs index 791e52e2df..bf19764a7e 100644 --- a/projects/Test/Integration/TestConnectionTopologyRecovery.cs +++ b/projects/Test/Integration/TestConnectionTopologyRecovery.cs @@ -96,7 +96,11 @@ public async Task TestTopologyRecoveryQueueFilter() }; AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryFilterAsync(filter); - conn.RecoverySucceeded += (source, ea) => tcs.SetResult(true); + conn.RecoverySucceeded += (source, ea) => + { + tcs.SetResult(true); + return Task.CompletedTask; + }; IChannel ch = await conn.CreateChannelAsync(); string queueToRecover = "recovered.queue"; @@ -142,7 +146,11 @@ public async Task TestTopologyRecoveryExchangeFilter() }; AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryFilterAsync(filter); - conn.RecoverySucceeded += (source, ea) => tcs.SetResult(true); + conn.RecoverySucceeded += (source, ea) => + { + tcs.SetResult(true); + return Task.CompletedTask; + }; IChannel ch = await conn.CreateChannelAsync(); try { @@ -186,7 +194,11 @@ public async Task TestTopologyRecoveryBindingFilter() }; AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryFilterAsync(filter); - conn.RecoverySucceeded += (source, ea) => tcs.SetResult(true); + conn.RecoverySucceeded += (source, ea) => + { + tcs.SetResult(true); + return Task.CompletedTask; + }; IChannel ch = await conn.CreateChannelAsync(); @@ -237,9 +249,21 @@ public async Task TestTopologyRecoveryDefaultFilterRecoversAllEntities() var connectionRecoveryTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var filter = new TopologyRecoveryFilter(); AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryFilterAsync(filter); - conn.RecoverySucceeded += (source, ea) => connectionRecoveryTcs.SetResult(true); - conn.ConnectionRecoveryError += (source, ea) => connectionRecoveryTcs.SetException(ea.Exception); - conn.CallbackException += (source, ea) => connectionRecoveryTcs.SetException(ea.Exception); + conn.RecoverySucceeded += (source, ea) => + { + connectionRecoveryTcs.SetResult(true); + return Task.CompletedTask; + }; + conn.ConnectionRecoveryError += (source, ea) => + { + connectionRecoveryTcs.SetException(ea.Exception); + return Task.CompletedTask; + }; + conn.CallbackException += (source, ea) => + { + connectionRecoveryTcs.SetException(ea.Exception); + return Task.CompletedTask; + }; IChannel ch = await conn.CreateChannelAsync(); try @@ -332,7 +356,11 @@ await channel.QueueDeclareAsync(rq.Name, false, false, false, }; AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryExceptionHandlerAsync(exceptionHandler); - conn.RecoverySucceeded += (source, ea) => tcs.SetResult(true); + conn.RecoverySucceeded += (source, ea) => + { + tcs.SetResult(true); + return Task.CompletedTask; + }; IChannel ch = await conn.CreateChannelAsync(); string queueToRecoverWithException = "recovery.exception.queue"; @@ -388,7 +416,11 @@ public async Task TestTopologyRecoveryExchangeExceptionHandler() }; AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryExceptionHandlerAsync(exceptionHandler); - conn.RecoverySucceeded += (source, ea) => tcs.SetResult(true); + conn.RecoverySucceeded += (source, ea) => + { + tcs.SetResult(true); + return Task.CompletedTask; + }; string exchangeToRecoverWithException = "recovery.exception.exchange"; string exchangeToRecoverSuccessfully = "successfully.recovered.exchange"; @@ -449,7 +481,11 @@ public async Task TestTopologyRecoveryBindingExceptionHandler() }; AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryExceptionHandlerAsync(exceptionHandler); - conn.RecoverySucceeded += (source, ea) => connectionRecoveryTcs.SetResult(true); + conn.RecoverySucceeded += (source, ea) => + { + connectionRecoveryTcs.SetResult(true); + return Task.CompletedTask; + }; IChannel ch = await conn.CreateChannelAsync(); const string queueWithRecoveredBinding = "successfully.recovered.queue"; @@ -511,7 +547,11 @@ public async Task TestTopologyRecoveryConsumerExceptionHandler() }; AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryExceptionHandlerAsync(exceptionHandler); - conn.RecoverySucceeded += (source, ea) => connectionRecoveryTcs.SetResult(true); + conn.RecoverySucceeded += (source, ea) => + { + connectionRecoveryTcs.SetResult(true); + return Task.CompletedTask; + }; IChannel ch = await conn.CreateChannelAsync(); try { diff --git a/projects/Test/Integration/TestFloodPublishing.cs b/projects/Test/Integration/TestFloodPublishing.cs index d9c1698bf5..020f1ad0a5 100644 --- a/projects/Test/Integration/TestFloodPublishing.cs +++ b/projects/Test/Integration/TestFloodPublishing.cs @@ -75,6 +75,7 @@ public async Task TestUnthrottledFloodPublishing() sawUnexpectedShutdown = true; } }); + return Task.CompletedTask; }; _channel.ChannelShutdown += (o, ea) => @@ -141,6 +142,7 @@ public async Task TestMultithreadFloodPublishing() allMessagesSeenTcs.TrySetException(args.Exception); } }); + return Task.CompletedTask; }; _channel.ChannelShutdown += (o, ea) => @@ -174,6 +176,7 @@ public async Task TestMultithreadFloodPublishing() allMessagesSeenTcs.TrySetException(args.Exception); } }); + return Task.CompletedTask; }; using (IChannel publishChannel = await publishConnection.CreateChannelAsync()) @@ -225,6 +228,7 @@ public async Task TestMultithreadFloodPublishing() allMessagesSeenTcs.TrySetException(args.Exception); } }); + return Task.CompletedTask; }; using (IChannel consumeChannel = await consumeConnection.CreateChannelAsync()) diff --git a/projects/Test/Integration/TestQueueDeclare.cs b/projects/Test/Integration/TestQueueDeclare.cs index 8ba26841b7..c27c2dedc5 100644 --- a/projects/Test/Integration/TestQueueDeclare.cs +++ b/projects/Test/Integration/TestQueueDeclare.cs @@ -71,6 +71,7 @@ public async Task TestConcurrentQueueDeclareAndBindAsync() sawShutdown = true; } }); + return Task.CompletedTask; }; _channel.ChannelShutdown += (o, ea) => diff --git a/projects/Test/Integration/TestToxiproxy.cs b/projects/Test/Integration/TestToxiproxy.cs index b6f2557575..48c093dada 100644 --- a/projects/Test/Integration/TestToxiproxy.cs +++ b/projects/Test/Integration/TestToxiproxy.cs @@ -89,12 +89,14 @@ public async Task TestCloseConnection() { _output.WriteLine($"[ERROR] unexpected callback exception {ea.Detail} {ea.Exception}"); recoverySucceededTcs.SetResult(false); + return Task.CompletedTask; }; conn.ConnectionRecoveryError += (s, ea) => { _output.WriteLine($"[ERROR] connection recovery error {ea.Exception}"); recoverySucceededTcs.SetResult(false); + return Task.CompletedTask; }; conn.ConnectionShutdown += (s, ea) => @@ -109,6 +111,7 @@ public async Task TestCloseConnection() * test exits, and connectionShutdownTcs will have already been set */ connectionShutdownTcs.TrySetResult(true); + return Task.CompletedTask; }; conn.RecoverySucceeded += (s, ea) => @@ -119,6 +122,7 @@ public async Task TestCloseConnection() } recoverySucceededTcs.SetResult(true); + return Task.CompletedTask; }; async Task PublishLoop() @@ -268,6 +272,7 @@ public async Task TestTcpReset_GH1464() conn.ConnectionShutdown += (o, ea) => { connectionShutdownTcs.SetResult(true); + return Task.CompletedTask; }; using (IChannel ch = await conn.CreateChannelAsync()) diff --git a/projects/Test/OAuth2/TestOAuth2.cs b/projects/Test/OAuth2/TestOAuth2.cs index 9a25b687d0..29d5f9f6e5 100644 --- a/projects/Test/OAuth2/TestOAuth2.cs +++ b/projects/Test/OAuth2/TestOAuth2.cs @@ -86,17 +86,20 @@ public async Task InitializeAsync() _connection.ConnectionShutdown += (sender, ea) => { _testOutputHelper.WriteLine("{0} [WARNING] connection shutdown!", DateTime.Now); + return Task.CompletedTask; }; _connection.ConnectionRecoveryError += (sender, ea) => { _testOutputHelper.WriteLine("{0} [ERROR] connection recovery error: {1}", DateTime.Now, ea.Exception); + return Task.CompletedTask; }; _connection.RecoverySucceeded += (sender, ea) => { _testOutputHelper.WriteLine("{0} [INFO] connection recovery succeeded", DateTime.Now); + return Task.CompletedTask; }; _credentialsRefresher = new CredentialsRefresher(_producerCredentialsProvider, diff --git a/projects/Test/SequentialIntegration/TestConnectionBlocked.cs b/projects/Test/SequentialIntegration/TestConnectionBlocked.cs index 591b39ba94..be10630272 100644 --- a/projects/Test/SequentialIntegration/TestConnectionBlocked.cs +++ b/projects/Test/SequentialIntegration/TestConnectionBlocked.cs @@ -60,14 +60,16 @@ public override async Task DisposeAsync() public async Task TestConnectionBlockedNotification() { var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - _conn.ConnectionBlocked += (object sender, ConnectionBlockedEventArgs args) => + _conn.ConnectionBlocked += async (object sender, ConnectionBlockedEventArgs args) => { - UnblockAsync(); + // TODO should this continue to be doing fire and forget? + await UnblockAsync(); }; _conn.ConnectionUnblocked += (object sender, EventArgs ea) => { tcs.SetResult(true); + return Task.CompletedTask; }; await BlockAsync(_channel); diff --git a/projects/Test/SequentialIntegration/TestConnectionBlockedChannelLeak.cs b/projects/Test/SequentialIntegration/TestConnectionBlockedChannelLeak.cs index e1f50e1a0d..7049e58f95 100644 --- a/projects/Test/SequentialIntegration/TestConnectionBlockedChannelLeak.cs +++ b/projects/Test/SequentialIntegration/TestConnectionBlockedChannelLeak.cs @@ -85,11 +85,13 @@ public async Task TestConnectionBlockedChannelLeak_GH1573() _conn.ConnectionBlocked += (object sender, ConnectionBlockedEventArgs args) => { connectionBlockedTcs.SetResult(true); + return Task.CompletedTask; }; _conn.ConnectionUnblocked += (object sender, EventArgs ea) => { connectionUnblockedTcs.SetResult(true); + return Task.CompletedTask; }; async Task ExchangeDeclareAndPublish() diff --git a/projects/Test/SequentialIntegration/TestConnectionRecovery.cs b/projects/Test/SequentialIntegration/TestConnectionRecovery.cs index 2edfa9f46e..9e3ea337f0 100644 --- a/projects/Test/SequentialIntegration/TestConnectionRecovery.cs +++ b/projects/Test/SequentialIntegration/TestConnectionRecovery.cs @@ -146,7 +146,11 @@ public async Task TestBlockedListenersRecovery() try { var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - _conn.ConnectionBlocked += (c, reason) => tcs.SetResult(true); + _conn.ConnectionBlocked += (c, reason) => + { + tcs.SetResult(true); + return Task.CompletedTask; + }; await CloseAndWaitForRecoveryAsync(); await CloseAndWaitForRecoveryAsync(); await BlockAsync(_channel); @@ -224,6 +228,7 @@ public async Task TestServerNamedTransientAutoDeleteQueueAndBindingRecovery() nameBefore = ea.NameBefore; nameAfter = ea.NameAfter; tcs.SetResult(true); + return Task.CompletedTask; }; await _channel.QueueBindAsync(queue: nameBefore, exchange: x, routingKey: ""); @@ -248,7 +253,11 @@ public async Task TestServerNamedTransientAutoDeleteQueueAndBindingRecovery() public async Task TestShutdownEventHandlersRecoveryOnConnectionAfterDelayedServerRestart() { int counter = 0; - _conn.ConnectionShutdown += (c, args) => Interlocked.Increment(ref counter); + _conn.ConnectionShutdown += (c, args) => + { + Interlocked.Increment(ref counter); + return Task.CompletedTask; + }; TaskCompletionSource shutdownLatch = PrepareForShutdown(_conn); TaskCompletionSource recoveryLatch = PrepareForRecovery((AutorecoveringConnection)_conn); @@ -284,9 +293,14 @@ public async Task TestShutdownEventHandlersRecoveryOnConnectionAfterTwoDelayedSe { // Uncomment for debugging // _output.WriteLine("[INFO] ConnectionRecoveryError: {0}", args.Exception); + return Task.CompletedTask; }; - aconn.ConnectionShutdown += (c, args) => Interlocked.Increment(ref counter); + aconn.ConnectionShutdown += (c, args) => + { + Interlocked.Increment(ref counter); + return Task.CompletedTask; + }; Assert.True(_conn.IsOpen); @@ -322,7 +336,11 @@ public async Task TestShutdownEventHandlersRecoveryOnConnectionAfterTwoDelayedSe public async Task TestUnblockedListenersRecovery() { var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - _conn.ConnectionUnblocked += (source, ea) => tcs.SetResult(true); + _conn.ConnectionUnblocked += (source, ea) => + { + tcs.SetResult(true); + return Task.CompletedTask; + }; await CloseAndWaitForRecoveryAsync(); await CloseAndWaitForRecoveryAsync(); await BlockAsync(_channel); diff --git a/projects/Test/SequentialIntegration/TestHeartbeats.cs b/projects/Test/SequentialIntegration/TestHeartbeats.cs index 38882e5694..08509118f7 100644 --- a/projects/Test/SequentialIntegration/TestHeartbeats.cs +++ b/projects/Test/SequentialIntegration/TestHeartbeats.cs @@ -117,6 +117,7 @@ public async Task TestHundredsOfConnectionsWithRandomHeartbeatInterval() conn.ConnectionShutdown += (sender, evt) => { CheckInitiator(evt); + return Task.CompletedTask; }; } @@ -149,6 +150,7 @@ private async Task RunSingleConnectionTestAsync(ConnectionFactory cf) wasShutdown = true; } } + return Task.CompletedTask; }; await SleepFor(30); From 7337fadf22e74c2d870073c095c7ea79debcc74d Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 09:17:43 -0700 Subject: [PATCH 02/18] Rename three internal async methods to use `Async` suffix. --- projects/RabbitMQ.Client/client/framing/Channel.cs | 4 ++-- projects/RabbitMQ.Client/client/impl/ChannelBase.cs | 8 ++++---- .../RabbitMQ.Client/client/impl/Connection.Commands.cs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/projects/RabbitMQ.Client/client/framing/Channel.cs b/projects/RabbitMQ.Client/client/framing/Channel.cs index b0d3cd28cc..68b5dc6fc7 100644 --- a/projects/RabbitMQ.Client/client/framing/Channel.cs +++ b/projects/RabbitMQ.Client/client/framing/Channel.cs @@ -118,7 +118,7 @@ protected override Task DispatchCommandAsync(IncomingCommand cmd, Cancella case ProtocolCommandId.ConnectionBlocked: { // Note: always returns true - return HandleConnectionBlocked(cmd, cancellationToken); + return HandleConnectionBlockedAsync(cmd, cancellationToken); } case ProtocolCommandId.ConnectionClose: { @@ -143,7 +143,7 @@ protected override Task DispatchCommandAsync(IncomingCommand cmd, Cancella case ProtocolCommandId.ConnectionUnblocked: { // Note: always returns true - return HandleConnectionUnblocked(cancellationToken); + return HandleConnectionUnblockedAsync(cancellationToken); } default: { diff --git a/projects/RabbitMQ.Client/client/impl/ChannelBase.cs b/projects/RabbitMQ.Client/client/impl/ChannelBase.cs index 0743cc9351..5ef55ed28d 100644 --- a/projects/RabbitMQ.Client/client/impl/ChannelBase.cs +++ b/projects/RabbitMQ.Client/client/impl/ChannelBase.cs @@ -701,10 +701,10 @@ await ModelSendAsync(method, cancellationToken). return true; } - protected async Task HandleConnectionBlocked(IncomingCommand cmd, CancellationToken cancellationToken) + protected async Task HandleConnectionBlockedAsync(IncomingCommand cmd, CancellationToken cancellationToken) { string reason = new ConnectionBlocked(cmd.MethodSpan)._reason; - await Session.Connection.HandleConnectionBlocked(reason) + await Session.Connection.HandleConnectionBlockedAsync(reason) .ConfigureAwait(false); return true; } @@ -780,9 +780,9 @@ await k.HandleCommandAsync(cmd) return true; } - protected async Task HandleConnectionUnblocked(CancellationToken cancellationToken) + protected async Task HandleConnectionUnblockedAsync(CancellationToken cancellationToken) { - await Session.Connection.HandleConnectionUnblocked() + await Session.Connection.HandleConnectionUnblockedAsync() .ConfigureAwait(false); return true; } diff --git a/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs b/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs index fc3e05761a..afb19e3cb6 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs @@ -54,7 +54,7 @@ internal void NotifyReceivedCloseOk() _closed = true; } - internal Task HandleConnectionBlocked(string reason) + internal Task HandleConnectionBlockedAsync(string reason) { if (!_connectionBlockedWrapper.IsEmpty) { @@ -63,7 +63,7 @@ internal Task HandleConnectionBlocked(string reason) return Task.CompletedTask; } - internal Task HandleConnectionUnblocked() + internal Task HandleConnectionUnblockedAsync() { if (!_connectionUnblockedWrapper.IsEmpty) { From 8c7f8f912f3897cd21d4744bd00379c1dca4c54e Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 10:03:41 -0700 Subject: [PATCH 03/18] Rename `CallbackException` event to `CallbackExceptionAsync` --- projects/RabbitMQ.Client/PublicAPI.Shipped.txt | 2 +- projects/RabbitMQ.Client/client/api/IConnection.cs | 2 +- .../client/impl/AutorecoveringConnection.cs | 6 +++--- projects/RabbitMQ.Client/client/impl/Connection.cs | 14 +++++++------- projects/Test/Common/IntegrationFixture.cs | 2 +- .../TestConnectionRecoveryWithoutSetup.cs | 2 +- .../Integration/TestConnectionTopologyRecovery.cs | 2 +- projects/Test/Integration/TestToxiproxy.cs | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt index 99dc613f82..47c2ba8ce0 100644 --- a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt +++ b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt @@ -445,7 +445,6 @@ RabbitMQ.Client.IChannel.IsClosed.get -> bool RabbitMQ.Client.IChannel.IsOpen.get -> bool RabbitMQ.Client.IChannelExtensions RabbitMQ.Client.IConnection -RabbitMQ.Client.IConnection.CallbackException -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.ChannelMax.get -> ushort RabbitMQ.Client.IConnection.ClientProperties.get -> System.Collections.Generic.IDictionary RabbitMQ.Client.IConnection.ClientProvidedName.get -> string @@ -895,3 +894,4 @@ RabbitMQ.Client.IChannel.ConfirmSelectAsync(bool trackConfirmations = true, Syst const RabbitMQ.Client.Constants.DefaultConsumerDispatchConcurrency = 1 -> ushort readonly RabbitMQ.Client.ConnectionConfig.ConsumerDispatchConcurrency -> ushort RabbitMQ.Client.IConnection.CreateChannelAsync(ushort? consumerDispatchConcurrency = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! +RabbitMQ.Client.IConnection.CallbackExceptionAsync -> RabbitMQ.Client.Events.AsyncEventHandler! diff --git a/projects/RabbitMQ.Client/client/api/IConnection.cs b/projects/RabbitMQ.Client/client/api/IConnection.cs index ed71b171d6..9f547e6688 100644 --- a/projects/RabbitMQ.Client/client/api/IConnection.cs +++ b/projects/RabbitMQ.Client/client/api/IConnection.cs @@ -143,7 +143,7 @@ public interface IConnection : INetworkConnection, IDisposable /// , then this event will be signalled whenever one /// of those event handlers throws an exception, as well. /// - event AsyncEventHandler CallbackException; + event AsyncEventHandler CallbackExceptionAsync; event AsyncEventHandler ConnectionBlocked; diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs index 3f68d42e42..50303f46ee 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs @@ -102,10 +102,10 @@ public event AsyncEventHandler ConnectionRecov } private AsyncEventingWrapper _connectionRecoveryErrorWrapper; - public event AsyncEventHandler CallbackException + public event AsyncEventHandler CallbackExceptionAsync { - add => InnerConnection.CallbackException += value; - remove => InnerConnection.CallbackException -= value; + add => InnerConnection.CallbackExceptionAsync += value; + remove => InnerConnection.CallbackExceptionAsync -= value; } public event AsyncEventHandler ConnectionBlocked diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index eac78e104b..269bc705c6 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -65,7 +65,7 @@ internal Connection(ConnectionConfig config, IFrameHandler frameHandler) _frameHandler = frameHandler; Func onException = (exception, context) => OnCallbackExceptionAsync(CallbackExceptionEventArgs.Build(exception, context)); - _callbackExceptionWrapper = new AsyncEventingWrapper(string.Empty, (exception, context) => Task.CompletedTask); + _callbackExceptionAsyncWrapper = new AsyncEventingWrapper(string.Empty, (exception, context) => Task.CompletedTask); _connectionBlockedWrapper = new AsyncEventingWrapper("OnConnectionBlocked", onException); _connectionUnblockedWrapper = new AsyncEventingWrapper("OnConnectionUnblocked", onException); _connectionShutdownWrapper = new AsyncEventingWrapper("OnShutdown", onException); @@ -118,12 +118,12 @@ internal IFrameHandler FrameHandler get { return _frameHandler; } } - public event AsyncEventHandler CallbackException + public event AsyncEventHandler CallbackExceptionAsync { - add => _callbackExceptionWrapper.AddHandler(value); - remove => _callbackExceptionWrapper.RemoveHandler(value); + add => _callbackExceptionAsyncWrapper.AddHandler(value); + remove => _callbackExceptionAsyncWrapper.RemoveHandler(value); } - private AsyncEventingWrapper _callbackExceptionWrapper; + private AsyncEventingWrapper _callbackExceptionAsyncWrapper; public event AsyncEventHandler ConnectionBlocked { @@ -207,7 +207,7 @@ public event AsyncEventHandler QueueName internal void TakeOver(Connection other) { - _callbackExceptionWrapper.Takeover(other._callbackExceptionWrapper); + _callbackExceptionAsyncWrapper.Takeover(other._callbackExceptionAsyncWrapper); _connectionBlockedWrapper.Takeover(other._connectionBlockedWrapper); _connectionUnblockedWrapper.Takeover(other._connectionUnblockedWrapper); _connectionShutdownWrapper.Takeover(other._connectionShutdownWrapper); @@ -464,7 +464,7 @@ private void LogCloseError(string error, Exception ex) internal Task OnCallbackExceptionAsync(CallbackExceptionEventArgs args) { - return _callbackExceptionWrapper.InvokeAsync(this, args); + return _callbackExceptionAsyncWrapper.InvokeAsync(this, args); } internal ValueTask WriteAsync(RentedMemory frames, CancellationToken cancellationToken) diff --git a/projects/Test/Common/IntegrationFixture.cs b/projects/Test/Common/IntegrationFixture.cs index 1de939280a..1f3a6ec4b5 100644 --- a/projects/Test/Common/IntegrationFixture.cs +++ b/projects/Test/Common/IntegrationFixture.cs @@ -240,7 +240,7 @@ protected void AddCallbackExceptionHandlers(IConnection conn, IChannel channel) return Task.CompletedTask; }; - conn.CallbackException += (o, ea) => + conn.CallbackExceptionAsync += (o, ea) => { _connectionCallbackException = ea.Exception; diff --git a/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs b/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs index 235845795d..c6b7f8d96c 100644 --- a/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs +++ b/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs @@ -300,7 +300,7 @@ public async Task TestTopologyRecoveryConsumerFilter() connectionRecoveryTcs.SetException(ea.Exception); return Task.CompletedTask; }; - conn.CallbackException += (source, ea) => + conn.CallbackExceptionAsync += (source, ea) => { connectionRecoveryTcs.SetException(ea.Exception); return Task.CompletedTask; diff --git a/projects/Test/Integration/TestConnectionTopologyRecovery.cs b/projects/Test/Integration/TestConnectionTopologyRecovery.cs index bf19764a7e..dcff364a72 100644 --- a/projects/Test/Integration/TestConnectionTopologyRecovery.cs +++ b/projects/Test/Integration/TestConnectionTopologyRecovery.cs @@ -259,7 +259,7 @@ public async Task TestTopologyRecoveryDefaultFilterRecoversAllEntities() connectionRecoveryTcs.SetException(ea.Exception); return Task.CompletedTask; }; - conn.CallbackException += (source, ea) => + conn.CallbackExceptionAsync += (source, ea) => { connectionRecoveryTcs.SetException(ea.Exception); return Task.CompletedTask; diff --git a/projects/Test/Integration/TestToxiproxy.cs b/projects/Test/Integration/TestToxiproxy.cs index 48c093dada..b8f4efb4d1 100644 --- a/projects/Test/Integration/TestToxiproxy.cs +++ b/projects/Test/Integration/TestToxiproxy.cs @@ -85,7 +85,7 @@ public async Task TestCloseConnection() { using (IConnection conn = await cf.CreateConnectionAsync()) { - conn.CallbackException += (s, ea) => + conn.CallbackExceptionAsync += (s, ea) => { _output.WriteLine($"[ERROR] unexpected callback exception {ea.Detail} {ea.Exception}"); recoverySucceededTcs.SetResult(false); From ebb8e88dcd5cea5591fea39fe35f273dc6ca08ea Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 10:06:59 -0700 Subject: [PATCH 04/18] Rename `ConnectionBlocked` to `ConnectionBlockedAsync` --- projects/RabbitMQ.Client/PublicAPI.Shipped.txt | 2 +- projects/RabbitMQ.Client/client/api/IConnection.cs | 2 +- .../client/impl/AutorecoveringConnection.cs | 6 +++--- .../client/impl/Connection.Commands.cs | 4 ++-- projects/RabbitMQ.Client/client/impl/Connection.cs | 12 ++++++------ .../SequentialIntegration/TestConnectionBlocked.cs | 2 +- .../TestConnectionBlockedChannelLeak.cs | 2 +- .../SequentialIntegration/TestConnectionRecovery.cs | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt index 47c2ba8ce0..b1b2ab0e9c 100644 --- a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt +++ b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt @@ -449,7 +449,6 @@ RabbitMQ.Client.IConnection.ChannelMax.get -> ushort RabbitMQ.Client.IConnection.ClientProperties.get -> System.Collections.Generic.IDictionary RabbitMQ.Client.IConnection.ClientProvidedName.get -> string RabbitMQ.Client.IConnection.CloseReason.get -> RabbitMQ.Client.ShutdownEventArgs -RabbitMQ.Client.IConnection.ConnectionBlocked -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.ConnectionRecoveryError -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.ConnectionShutdown -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.ConnectionUnblocked -> RabbitMQ.Client.Events.AsyncEventHandler @@ -895,3 +894,4 @@ const RabbitMQ.Client.Constants.DefaultConsumerDispatchConcurrency = 1 -> ushort readonly RabbitMQ.Client.ConnectionConfig.ConsumerDispatchConcurrency -> ushort RabbitMQ.Client.IConnection.CreateChannelAsync(ushort? consumerDispatchConcurrency = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! RabbitMQ.Client.IConnection.CallbackExceptionAsync -> RabbitMQ.Client.Events.AsyncEventHandler! +RabbitMQ.Client.IConnection.ConnectionBlockedAsync -> RabbitMQ.Client.Events.AsyncEventHandler! diff --git a/projects/RabbitMQ.Client/client/api/IConnection.cs b/projects/RabbitMQ.Client/client/api/IConnection.cs index 9f547e6688..54c1a5c448 100644 --- a/projects/RabbitMQ.Client/client/api/IConnection.cs +++ b/projects/RabbitMQ.Client/client/api/IConnection.cs @@ -145,7 +145,7 @@ public interface IConnection : INetworkConnection, IDisposable /// event AsyncEventHandler CallbackExceptionAsync; - event AsyncEventHandler ConnectionBlocked; + event AsyncEventHandler ConnectionBlockedAsync; /// /// Raised when the connection is destroyed. diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs index 50303f46ee..3457baa0b5 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs @@ -108,10 +108,10 @@ public event AsyncEventHandler CallbackExceptionAsyn remove => InnerConnection.CallbackExceptionAsync -= value; } - public event AsyncEventHandler ConnectionBlocked + public event AsyncEventHandler ConnectionBlockedAsync { - add => InnerConnection.ConnectionBlocked += value; - remove => InnerConnection.ConnectionBlocked -= value; + add => InnerConnection.ConnectionBlockedAsync += value; + remove => InnerConnection.ConnectionBlockedAsync -= value; } public event AsyncEventHandler ConnectionShutdown diff --git a/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs b/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs index afb19e3cb6..bef6a12587 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs @@ -56,9 +56,9 @@ internal void NotifyReceivedCloseOk() internal Task HandleConnectionBlockedAsync(string reason) { - if (!_connectionBlockedWrapper.IsEmpty) + if (!_connectionBlockedAsyncWrapper.IsEmpty) { - return _connectionBlockedWrapper.InvokeAsync(this, new ConnectionBlockedEventArgs(reason)); + return _connectionBlockedAsyncWrapper.InvokeAsync(this, new ConnectionBlockedEventArgs(reason)); } return Task.CompletedTask; } diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index 269bc705c6..20a38a7461 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -66,7 +66,7 @@ internal Connection(ConnectionConfig config, IFrameHandler frameHandler) Func onException = (exception, context) => OnCallbackExceptionAsync(CallbackExceptionEventArgs.Build(exception, context)); _callbackExceptionAsyncWrapper = new AsyncEventingWrapper(string.Empty, (exception, context) => Task.CompletedTask); - _connectionBlockedWrapper = new AsyncEventingWrapper("OnConnectionBlocked", onException); + _connectionBlockedAsyncWrapper = new AsyncEventingWrapper("OnConnectionBlocked", onException); _connectionUnblockedWrapper = new AsyncEventingWrapper("OnConnectionUnblocked", onException); _connectionShutdownWrapper = new AsyncEventingWrapper("OnShutdown", onException); @@ -125,12 +125,12 @@ public event AsyncEventHandler CallbackExceptionAsyn } private AsyncEventingWrapper _callbackExceptionAsyncWrapper; - public event AsyncEventHandler ConnectionBlocked + public event AsyncEventHandler ConnectionBlockedAsync { - add => _connectionBlockedWrapper.AddHandler(value); - remove => _connectionBlockedWrapper.RemoveHandler(value); + add => _connectionBlockedAsyncWrapper.AddHandler(value); + remove => _connectionBlockedAsyncWrapper.RemoveHandler(value); } - private AsyncEventingWrapper _connectionBlockedWrapper; + private AsyncEventingWrapper _connectionBlockedAsyncWrapper; public event AsyncEventHandler ConnectionUnblocked { @@ -208,7 +208,7 @@ public event AsyncEventHandler QueueName internal void TakeOver(Connection other) { _callbackExceptionAsyncWrapper.Takeover(other._callbackExceptionAsyncWrapper); - _connectionBlockedWrapper.Takeover(other._connectionBlockedWrapper); + _connectionBlockedAsyncWrapper.Takeover(other._connectionBlockedAsyncWrapper); _connectionUnblockedWrapper.Takeover(other._connectionUnblockedWrapper); _connectionShutdownWrapper.Takeover(other._connectionShutdownWrapper); // TODO Why are other wrappers not taken over? diff --git a/projects/Test/SequentialIntegration/TestConnectionBlocked.cs b/projects/Test/SequentialIntegration/TestConnectionBlocked.cs index be10630272..18d8160612 100644 --- a/projects/Test/SequentialIntegration/TestConnectionBlocked.cs +++ b/projects/Test/SequentialIntegration/TestConnectionBlocked.cs @@ -60,7 +60,7 @@ public override async Task DisposeAsync() public async Task TestConnectionBlockedNotification() { var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - _conn.ConnectionBlocked += async (object sender, ConnectionBlockedEventArgs args) => + _conn.ConnectionBlockedAsync += async (object sender, ConnectionBlockedEventArgs args) => { // TODO should this continue to be doing fire and forget? await UnblockAsync(); diff --git a/projects/Test/SequentialIntegration/TestConnectionBlockedChannelLeak.cs b/projects/Test/SequentialIntegration/TestConnectionBlockedChannelLeak.cs index 7049e58f95..a08f5256fd 100644 --- a/projects/Test/SequentialIntegration/TestConnectionBlockedChannelLeak.cs +++ b/projects/Test/SequentialIntegration/TestConnectionBlockedChannelLeak.cs @@ -82,7 +82,7 @@ public async Task TestConnectionBlockedChannelLeak_GH1573() string exchangeName = GenerateExchangeName(); - _conn.ConnectionBlocked += (object sender, ConnectionBlockedEventArgs args) => + _conn.ConnectionBlockedAsync += (object sender, ConnectionBlockedEventArgs args) => { connectionBlockedTcs.SetResult(true); return Task.CompletedTask; diff --git a/projects/Test/SequentialIntegration/TestConnectionRecovery.cs b/projects/Test/SequentialIntegration/TestConnectionRecovery.cs index 9e3ea337f0..7884449703 100644 --- a/projects/Test/SequentialIntegration/TestConnectionRecovery.cs +++ b/projects/Test/SequentialIntegration/TestConnectionRecovery.cs @@ -146,7 +146,7 @@ public async Task TestBlockedListenersRecovery() try { var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - _conn.ConnectionBlocked += (c, reason) => + _conn.ConnectionBlockedAsync += (c, reason) => { tcs.SetResult(true); return Task.CompletedTask; From 5082dc6afc68990bdf8c377e6ce422ba018d7f9c Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 10:10:04 -0700 Subject: [PATCH 05/18] Rename `ConnectionShutdown` to `ConnectionShutdownAsync` --- projects/RabbitMQ.Client/PublicAPI.Shipped.txt | 2 +- .../RabbitMQ.Client/client/api/IConnection.cs | 2 +- .../client/impl/AutorecoveringConnection.cs | 8 ++++---- .../RabbitMQ.Client/client/impl/Connection.cs | 14 +++++++------- .../RabbitMQ.Client/client/impl/SessionBase.cs | 4 ++-- .../Test/Applications/MassPublish/Program.cs | 6 +++--- projects/Test/Common/IntegrationFixture.cs | 4 ++-- .../Test/Common/TestConnectionRecoveryBase.cs | 2 +- .../Connection/TestShutdownEventHandlers.cs | 2 +- projects/Test/Integration/TestAsyncConsumer.cs | 16 ++++++++-------- projects/Test/Integration/TestBasicPublish.cs | 2 +- .../TestConcurrentAccessWithSharedConnection.cs | 2 +- projects/Test/Integration/TestFloodPublishing.cs | 8 ++++---- .../Integration/TestPublishSharedChannelAsync.cs | 2 +- projects/Test/Integration/TestQueueDeclare.cs | 2 +- projects/Test/Integration/TestToxiproxy.cs | 4 ++-- projects/Test/OAuth2/TestOAuth2.cs | 2 +- .../TestConnectionRecovery.cs | 4 ++-- .../Test/SequentialIntegration/TestHeartbeats.cs | 4 ++-- 19 files changed, 45 insertions(+), 45 deletions(-) diff --git a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt index b1b2ab0e9c..39720856cb 100644 --- a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt +++ b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt @@ -450,7 +450,6 @@ RabbitMQ.Client.IConnection.ClientProperties.get -> System.Collections.Generic.I RabbitMQ.Client.IConnection.ClientProvidedName.get -> string RabbitMQ.Client.IConnection.CloseReason.get -> RabbitMQ.Client.ShutdownEventArgs RabbitMQ.Client.IConnection.ConnectionRecoveryError -> RabbitMQ.Client.Events.AsyncEventHandler -RabbitMQ.Client.IConnection.ConnectionShutdown -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.ConnectionUnblocked -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.ConsumerTagChangeAfterRecovery -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.Endpoint.get -> RabbitMQ.Client.AmqpTcpEndpoint @@ -895,3 +894,4 @@ readonly RabbitMQ.Client.ConnectionConfig.ConsumerDispatchConcurrency -> ushort RabbitMQ.Client.IConnection.CreateChannelAsync(ushort? consumerDispatchConcurrency = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! RabbitMQ.Client.IConnection.CallbackExceptionAsync -> RabbitMQ.Client.Events.AsyncEventHandler! RabbitMQ.Client.IConnection.ConnectionBlockedAsync -> RabbitMQ.Client.Events.AsyncEventHandler! +RabbitMQ.Client.IConnection.ConnectionShutdownAsync -> RabbitMQ.Client.Events.AsyncEventHandler! diff --git a/projects/RabbitMQ.Client/client/api/IConnection.cs b/projects/RabbitMQ.Client/client/api/IConnection.cs index 54c1a5c448..4edbe4ebd1 100644 --- a/projects/RabbitMQ.Client/client/api/IConnection.cs +++ b/projects/RabbitMQ.Client/client/api/IConnection.cs @@ -155,7 +155,7 @@ public interface IConnection : INetworkConnection, IDisposable /// event handler is added to this event, the event handler /// will be fired immediately. /// - event AsyncEventHandler ConnectionShutdown; + event AsyncEventHandler ConnectionShutdownAsync; /// /// Raised when the connection completes recovery. diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs index 3457baa0b5..12e3c49324 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs @@ -66,7 +66,7 @@ internal AutorecoveringConnection(ConnectionConfig config, IEndpointResolver end _endpoints = endpoints; _innerConnection = innerConnection; - ConnectionShutdown += HandleConnectionShutdown; + ConnectionShutdownAsync += HandleConnectionShutdown; _recoverySucceededWrapper = new AsyncEventingWrapper("OnConnectionRecovery", onExceptionAsync); _connectionRecoveryErrorWrapper = new AsyncEventingWrapper("OnConnectionRecoveryError", onExceptionAsync); _consumerTagChangeAfterRecoveryWrapper = new AsyncEventingWrapper("OnConsumerRecovery", onExceptionAsync); @@ -114,10 +114,10 @@ public event AsyncEventHandler ConnectionBlockedAsyn remove => InnerConnection.ConnectionBlockedAsync -= value; } - public event AsyncEventHandler ConnectionShutdown + public event AsyncEventHandler ConnectionShutdownAsync { - add => InnerConnection.ConnectionShutdown += value; - remove => InnerConnection.ConnectionShutdown -= value; + add => InnerConnection.ConnectionShutdownAsync += value; + remove => InnerConnection.ConnectionShutdownAsync -= value; } public event AsyncEventHandler ConnectionUnblocked diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index 20a38a7461..a1a9e24d5b 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -68,7 +68,7 @@ internal Connection(ConnectionConfig config, IFrameHandler frameHandler) _callbackExceptionAsyncWrapper = new AsyncEventingWrapper(string.Empty, (exception, context) => Task.CompletedTask); _connectionBlockedAsyncWrapper = new AsyncEventingWrapper("OnConnectionBlocked", onException); _connectionUnblockedWrapper = new AsyncEventingWrapper("OnConnectionUnblocked", onException); - _connectionShutdownWrapper = new AsyncEventingWrapper("OnShutdown", onException); + _connectionShutdownAsyncWrapper = new AsyncEventingWrapper("OnShutdown", onException); _sessionManager = new SessionManager(this, 0, config.MaxInboundMessageBodySize); _session0 = new MainSession(this, config.MaxInboundMessageBodySize); @@ -146,7 +146,7 @@ public event AsyncEventHandler RecoveringConsumer } private AsyncEventingWrapper _consumerAboutToBeRecoveredWrapper; - public event AsyncEventHandler ConnectionShutdown + public event AsyncEventHandler ConnectionShutdownAsync { add { @@ -154,7 +154,7 @@ public event AsyncEventHandler ConnectionShutdown ShutdownEventArgs? reason = CloseReason; if (reason is null) { - _connectionShutdownWrapper.AddHandler(value); + _connectionShutdownAsyncWrapper.AddHandler(value); } else { @@ -164,10 +164,10 @@ public event AsyncEventHandler ConnectionShutdown remove { ThrowIfDisposed(); - _connectionShutdownWrapper.RemoveHandler(value); + _connectionShutdownAsyncWrapper.RemoveHandler(value); } } - private AsyncEventingWrapper _connectionShutdownWrapper; + private AsyncEventingWrapper _connectionShutdownAsyncWrapper; /// /// This event is never fired by non-recovering connections but it is a part of the interface. @@ -210,7 +210,7 @@ internal void TakeOver(Connection other) _callbackExceptionAsyncWrapper.Takeover(other._callbackExceptionAsyncWrapper); _connectionBlockedAsyncWrapper.Takeover(other._connectionBlockedAsyncWrapper); _connectionUnblockedWrapper.Takeover(other._connectionUnblockedWrapper); - _connectionShutdownWrapper.Takeover(other._connectionShutdownWrapper); + _connectionShutdownAsyncWrapper.Takeover(other._connectionShutdownAsyncWrapper); // TODO Why are other wrappers not taken over? } @@ -436,7 +436,7 @@ private async Task FinishCloseAsync(CancellationToken cancellationToken) private Task OnShutdown(ShutdownEventArgs reason) { ThrowIfDisposed(); - return _connectionShutdownWrapper.InvokeAsync(this, reason); + return _connectionShutdownAsyncWrapper.InvokeAsync(this, reason); } private bool SetCloseReason(ShutdownEventArgs reason) diff --git a/projects/RabbitMQ.Client/client/impl/SessionBase.cs b/projects/RabbitMQ.Client/client/impl/SessionBase.cs index 5f8a0b63c1..77c970da2e 100644 --- a/projects/RabbitMQ.Client/client/impl/SessionBase.cs +++ b/projects/RabbitMQ.Client/client/impl/SessionBase.cs @@ -53,7 +53,7 @@ protected SessionBase(Connection connection, ushort channelNumber) ChannelNumber = channelNumber; if (channelNumber != 0) { - connection.ConnectionShutdown += OnConnectionShutdownAsync; + connection.ConnectionShutdownAsync += OnConnectionShutdownAsync; } RabbitMqClientEventSource.Log.ChannelOpened(); } @@ -94,7 +94,7 @@ public virtual Task OnConnectionShutdownAsync(object? conn, ShutdownEventArgs re public virtual void OnSessionShutdown(ShutdownEventArgs reason) { - Connection.ConnectionShutdown -= OnConnectionShutdownAsync; + Connection.ConnectionShutdownAsync -= OnConnectionShutdownAsync; _sessionShutdownWrapper.Invoke(this, reason); } diff --git a/projects/Test/Applications/MassPublish/Program.cs b/projects/Test/Applications/MassPublish/Program.cs index 7d06b48956..980212d34a 100644 --- a/projects/Test/Applications/MassPublish/Program.cs +++ b/projects/Test/Applications/MassPublish/Program.cs @@ -68,7 +68,7 @@ static Program() static async Task Main() { using IConnection consumeConnection = await s_consumeConnectionFactory.CreateConnectionAsync(); - consumeConnection.ConnectionShutdown += ConnectionConnectionShutdown; + consumeConnection.ConnectionShutdownAsync += ConnectionShutdownAsync; using IChannel consumeChannel = await consumeConnection.CreateChannelAsync(); consumeChannel.ChannelShutdown += Channel_ChannelShutdown; @@ -92,7 +92,7 @@ await consumeChannel.BasicConsumeAsync(queue: QueueName, autoAck: true, consumer for (int i = 0; i < ConnectionCount; i++) { IConnection publishConnection = await s_publishConnectionFactory.CreateConnectionAsync($"{AppId}-PUBLISH-{i}"); - publishConnection.ConnectionShutdown += ConnectionConnectionShutdown; + publishConnection.ConnectionShutdownAsync += ConnectionShutdownAsync; publishConnections.Add(publishConnection); } @@ -163,7 +163,7 @@ private static void PublishChannel_BasicNacks(object sender, BasicNackEventArgs Console.Error.WriteLine("[ERROR] unexpected nack on publish: {0}", e); } - private static Task ConnectionConnectionShutdown(object sender, ShutdownEventArgs e) + private static Task ConnectionShutdownAsync(object sender, ShutdownEventArgs e) { if (e.Initiator != ShutdownInitiator.Application) { diff --git a/projects/Test/Common/IntegrationFixture.cs b/projects/Test/Common/IntegrationFixture.cs index 1f3a6ec4b5..679a86e0d3 100644 --- a/projects/Test/Common/IntegrationFixture.cs +++ b/projects/Test/Common/IntegrationFixture.cs @@ -278,7 +278,7 @@ protected void AddCallbackShutdownHandlers() { if (_conn != null) { - _conn.ConnectionShutdown += (o, ea) => + _conn.ConnectionShutdownAsync += (o, ea) => { HandleConnectionShutdown(_conn, ea, (args) => { @@ -531,7 +531,7 @@ protected ConnectionFactory CreateConnectionFactory( }; } - protected Task HandleConnectionShutdown(object sender, ShutdownEventArgs args) + protected Task HandleConnectionShutdownAsync(object sender, ShutdownEventArgs args) { if (args.Initiator != ShutdownInitiator.Application) { diff --git a/projects/Test/Common/TestConnectionRecoveryBase.cs b/projects/Test/Common/TestConnectionRecoveryBase.cs index a10403f9ee..150e919e32 100644 --- a/projects/Test/Common/TestConnectionRecoveryBase.cs +++ b/projects/Test/Common/TestConnectionRecoveryBase.cs @@ -229,7 +229,7 @@ protected static TaskCompletionSource PrepareForShutdown(IConnection conn) var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); AutorecoveringConnection aconn = conn as AutorecoveringConnection; - aconn.ConnectionShutdown += (c, args) => + aconn.ConnectionShutdownAsync += (c, args) => { tcs.TrySetResult(true); return Task.CompletedTask; diff --git a/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestShutdownEventHandlers.cs b/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestShutdownEventHandlers.cs index a189edc5dc..b4b509a45b 100644 --- a/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestShutdownEventHandlers.cs +++ b/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestShutdownEventHandlers.cs @@ -46,7 +46,7 @@ public TestShutdownEventHandlers(ITestOutputHelper output) : base(output) public async Task TestShutdownEventHandlers_Called() { int counter = 0; - _conn.ConnectionShutdown += (c, args) => + _conn.ConnectionShutdownAsync += (c, args) => { Interlocked.Increment(ref counter); return Task.CompletedTask; diff --git a/projects/Test/Integration/TestAsyncConsumer.cs b/projects/Test/Integration/TestAsyncConsumer.cs index 4e1e37cf0c..8e7b594057 100644 --- a/projects/Test/Integration/TestAsyncConsumer.cs +++ b/projects/Test/Integration/TestAsyncConsumer.cs @@ -87,7 +87,7 @@ public async Task TestBasicRoundtripConcurrent() bool body2Received = false; try { - _conn.ConnectionShutdown += (o, ea) => + _conn.ConnectionShutdownAsync += (o, ea) => { HandleConnectionShutdown(_conn, ea, (args) => { @@ -180,7 +180,7 @@ public async Task TestBasicRoundtripConcurrentManyMessages() try { - _conn.ConnectionShutdown += (o, ea) => + _conn.ConnectionShutdownAsync += (o, ea) => { HandleConnectionShutdown(_conn, ea, (args) => { @@ -204,7 +204,7 @@ public async Task TestBasicRoundtripConcurrentManyMessages() { using (IConnection publishConn = await _connFactory.CreateConnectionAsync()) { - publishConn.ConnectionShutdown += (o, ea) => + publishConn.ConnectionShutdownAsync += (o, ea) => { HandleConnectionShutdown(publishConn, ea, (args) => { @@ -248,7 +248,7 @@ public async Task TestBasicRoundtripConcurrentManyMessages() { using (IConnection consumeConn = await _connFactory.CreateConnectionAsync()) { - consumeConn.ConnectionShutdown += (o, ea) => + consumeConn.ConnectionShutdownAsync += (o, ea) => { HandleConnectionShutdown(consumeConn, ea, (args) => { @@ -347,7 +347,7 @@ public async Task TestBasicRejectAsync() try { - _conn.ConnectionShutdown += (o, ea) => + _conn.ConnectionShutdownAsync += (o, ea) => { HandleConnectionShutdown(_conn, ea, (args) => { @@ -444,7 +444,7 @@ public async Task TestBasicAckAsync() var publishSyncSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - _conn.ConnectionShutdown += (o, ea) => + _conn.ConnectionShutdownAsync += (o, ea) => { HandleConnectionShutdown(_conn, ea, (args) => { @@ -509,7 +509,7 @@ public async Task TestBasicNackAsync() var publishSyncSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - _conn.ConnectionShutdown += (o, ea) => + _conn.ConnectionShutdownAsync += (o, ea) => { HandleConnectionShutdown(_conn, ea, (args) => { @@ -616,7 +616,7 @@ public async Task TestCreateChannelWithinAsyncConsumerCallback_GH650() tcs.SetCanceled(); }); - _conn.ConnectionShutdown += (o, ea) => + _conn.ConnectionShutdownAsync += (o, ea) => { HandleConnectionShutdown(_conn, ea, (args) => { diff --git a/projects/Test/Integration/TestBasicPublish.cs b/projects/Test/Integration/TestBasicPublish.cs index 379e2bfa07..648dcbf45b 100644 --- a/projects/Test/Integration/TestBasicPublish.cs +++ b/projects/Test/Integration/TestBasicPublish.cs @@ -202,7 +202,7 @@ public async Task TestMaxInboundMessageBodySize() using (IConnection conn = await cf.CreateConnectionAsync()) { - conn.ConnectionShutdown += (o, a) => + conn.ConnectionShutdownAsync += (o, a) => { sawConnectionShutdown = true; return Task.CompletedTask; diff --git a/projects/Test/Integration/TestConcurrentAccessWithSharedConnection.cs b/projects/Test/Integration/TestConcurrentAccessWithSharedConnection.cs index 0d6492360c..0ab5532297 100644 --- a/projects/Test/Integration/TestConcurrentAccessWithSharedConnection.cs +++ b/projects/Test/Integration/TestConcurrentAccessWithSharedConnection.cs @@ -50,7 +50,7 @@ public override async Task InitializeAsync() { _connFactory = CreateConnectionFactory(); _conn = await _connFactory.CreateConnectionAsync(); - _conn.ConnectionShutdown += HandleConnectionShutdown; + _conn.ConnectionShutdownAsync += HandleConnectionShutdownAsync; // NB: not creating _channel because this test suite doesn't use it. Assert.Null(_channel); } diff --git a/projects/Test/Integration/TestFloodPublishing.cs b/projects/Test/Integration/TestFloodPublishing.cs index 020f1ad0a5..3b4521ef35 100644 --- a/projects/Test/Integration/TestFloodPublishing.cs +++ b/projects/Test/Integration/TestFloodPublishing.cs @@ -66,7 +66,7 @@ public async Task TestUnthrottledFloodPublishing() Assert.IsNotType(_conn); _channel = await _conn.CreateChannelAsync(); - _conn.ConnectionShutdown += (_, ea) => + _conn.ConnectionShutdownAsync += (_, ea) => { HandleConnectionShutdown(_conn, ea, (args) => { @@ -132,7 +132,7 @@ public async Task TestMultithreadFloodPublishing() var allMessagesSeenTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - _conn.ConnectionShutdown += (o, ea) => + _conn.ConnectionShutdownAsync += (o, ea) => { HandleConnectionShutdown(_conn, ea, (args) => { @@ -166,7 +166,7 @@ public async Task TestMultithreadFloodPublishing() bool stop = false; using (IConnection publishConnection = await _connFactory.CreateConnectionAsync()) { - publishConnection.ConnectionShutdown += (o, ea) => + publishConnection.ConnectionShutdownAsync += (o, ea) => { HandleConnectionShutdown(_conn, ea, (args) => { @@ -218,7 +218,7 @@ public async Task TestMultithreadFloodPublishing() { using (IConnection consumeConnection = await _connFactory.CreateConnectionAsync()) { - consumeConnection.ConnectionShutdown += (o, ea) => + consumeConnection.ConnectionShutdownAsync += (o, ea) => { HandleConnectionShutdown(_conn, ea, (args) => { diff --git a/projects/Test/Integration/TestPublishSharedChannelAsync.cs b/projects/Test/Integration/TestPublishSharedChannelAsync.cs index 7c7d094ca0..3c508d087a 100644 --- a/projects/Test/Integration/TestPublishSharedChannelAsync.cs +++ b/projects/Test/Integration/TestPublishSharedChannelAsync.cs @@ -78,7 +78,7 @@ public async Task MultiThreadPublishOnSharedChannel() try { Assert.IsNotType(conn); - conn.ConnectionShutdown += HandleConnectionShutdown; + conn.ConnectionShutdownAsync += HandleConnectionShutdownAsync; using (IChannel channel = await conn.CreateChannelAsync()) { diff --git a/projects/Test/Integration/TestQueueDeclare.cs b/projects/Test/Integration/TestQueueDeclare.cs index c27c2dedc5..fc6315983b 100644 --- a/projects/Test/Integration/TestQueueDeclare.cs +++ b/projects/Test/Integration/TestQueueDeclare.cs @@ -62,7 +62,7 @@ public async Task TestConcurrentQueueDeclareAndBindAsync() { bool sawShutdown = false; - _conn.ConnectionShutdown += (o, ea) => + _conn.ConnectionShutdownAsync += (o, ea) => { HandleConnectionShutdown(_conn, ea, (args) => { diff --git a/projects/Test/Integration/TestToxiproxy.cs b/projects/Test/Integration/TestToxiproxy.cs index b8f4efb4d1..f4f47afb60 100644 --- a/projects/Test/Integration/TestToxiproxy.cs +++ b/projects/Test/Integration/TestToxiproxy.cs @@ -99,7 +99,7 @@ public async Task TestCloseConnection() return Task.CompletedTask; }; - conn.ConnectionShutdown += (s, ea) => + conn.ConnectionShutdownAsync += (s, ea) => { if (IsVerbose) { @@ -269,7 +269,7 @@ public async Task TestTcpReset_GH1464() { using (IConnection conn = await cf.CreateConnectionAsync()) { - conn.ConnectionShutdown += (o, ea) => + conn.ConnectionShutdownAsync += (o, ea) => { connectionShutdownTcs.SetResult(true); return Task.CompletedTask; diff --git a/projects/Test/OAuth2/TestOAuth2.cs b/projects/Test/OAuth2/TestOAuth2.cs index 29d5f9f6e5..b2bdb1ab92 100644 --- a/projects/Test/OAuth2/TestOAuth2.cs +++ b/projects/Test/OAuth2/TestOAuth2.cs @@ -83,7 +83,7 @@ public async Task InitializeAsync() _connection = await _connectionFactory.CreateConnectionAsync(_cancellationTokenSource.Token); - _connection.ConnectionShutdown += (sender, ea) => + _connection.ConnectionShutdownAsync += (sender, ea) => { _testOutputHelper.WriteLine("{0} [WARNING] connection shutdown!", DateTime.Now); return Task.CompletedTask; diff --git a/projects/Test/SequentialIntegration/TestConnectionRecovery.cs b/projects/Test/SequentialIntegration/TestConnectionRecovery.cs index 7884449703..ea8c9045ff 100644 --- a/projects/Test/SequentialIntegration/TestConnectionRecovery.cs +++ b/projects/Test/SequentialIntegration/TestConnectionRecovery.cs @@ -253,7 +253,7 @@ public async Task TestServerNamedTransientAutoDeleteQueueAndBindingRecovery() public async Task TestShutdownEventHandlersRecoveryOnConnectionAfterDelayedServerRestart() { int counter = 0; - _conn.ConnectionShutdown += (c, args) => + _conn.ConnectionShutdownAsync += (c, args) => { Interlocked.Increment(ref counter); return Task.CompletedTask; @@ -296,7 +296,7 @@ public async Task TestShutdownEventHandlersRecoveryOnConnectionAfterTwoDelayedSe return Task.CompletedTask; }; - aconn.ConnectionShutdown += (c, args) => + aconn.ConnectionShutdownAsync += (c, args) => { Interlocked.Increment(ref counter); return Task.CompletedTask; diff --git a/projects/Test/SequentialIntegration/TestHeartbeats.cs b/projects/Test/SequentialIntegration/TestHeartbeats.cs index 08509118f7..7699e56601 100644 --- a/projects/Test/SequentialIntegration/TestHeartbeats.cs +++ b/projects/Test/SequentialIntegration/TestHeartbeats.cs @@ -114,7 +114,7 @@ public async Task TestHundredsOfConnectionsWithRandomHeartbeatInterval() IConnection conn = await cf.CreateConnectionAsync($"{_testDisplayName}:{i}"); conns.Add(conn); IChannel ch = await conn.CreateChannelAsync(); - conn.ConnectionShutdown += (sender, evt) => + conn.ConnectionShutdownAsync += (sender, evt) => { CheckInitiator(evt); return Task.CompletedTask; @@ -140,7 +140,7 @@ private async Task RunSingleConnectionTestAsync(ConnectionFactory cf) { bool wasShutdown = false; - conn.ConnectionShutdown += (sender, evt) => + conn.ConnectionShutdownAsync += (sender, evt) => { lock (conn) { From 209fc7d04b287fe2601e722658d46c7cc811b6ea Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 10:26:39 -0700 Subject: [PATCH 06/18] Rename `RecoverySucceeded` to `RecoverySucceededAsync` --- projects/RabbitMQ.Client/PublicAPI.Shipped.txt | 2 +- .../RabbitMQ.Client/client/api/IConnection.cs | 2 +- .../impl/AutorecoveringConnection.Recovery.cs | 2 +- .../client/impl/AutorecoveringConnection.cs | 10 +++++----- .../RabbitMQ.Client/client/impl/Connection.cs | 2 +- projects/Test/Common/IntegrationFixture.cs | 2 +- .../TestRecoverySucceededEventHandlers.cs | 2 +- .../ConnectionRecovery/TestQueueRecovery.cs | 2 +- .../TestConnectionRecoveryWithoutSetup.cs | 2 +- .../TestConnectionTopologyRecovery.cs | 16 ++++++++-------- projects/Test/Integration/TestToxiproxy.cs | 2 +- projects/Test/OAuth2/TestOAuth2.cs | 2 +- 12 files changed, 23 insertions(+), 23 deletions(-) diff --git a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt index 39720856cb..4210794d56 100644 --- a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt +++ b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt @@ -459,7 +459,6 @@ RabbitMQ.Client.IConnection.IsOpen.get -> bool RabbitMQ.Client.IConnection.Protocol.get -> RabbitMQ.Client.IProtocol RabbitMQ.Client.IConnection.QueueNameChangedAfterRecovery -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.RecoveringConsumer -> RabbitMQ.Client.Events.AsyncEventHandler -RabbitMQ.Client.IConnection.RecoverySucceeded -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.ServerProperties.get -> System.Collections.Generic.IDictionary RabbitMQ.Client.IConnection.ShutdownReport.get -> System.Collections.Generic.IEnumerable RabbitMQ.Client.IConnectionExtensions @@ -895,3 +894,4 @@ RabbitMQ.Client.IConnection.CreateChannelAsync(ushort? consumerDispatchConcurren RabbitMQ.Client.IConnection.CallbackExceptionAsync -> RabbitMQ.Client.Events.AsyncEventHandler! RabbitMQ.Client.IConnection.ConnectionBlockedAsync -> RabbitMQ.Client.Events.AsyncEventHandler! RabbitMQ.Client.IConnection.ConnectionShutdownAsync -> RabbitMQ.Client.Events.AsyncEventHandler! +RabbitMQ.Client.IConnection.RecoverySucceededAsync -> RabbitMQ.Client.Events.AsyncEventHandler! diff --git a/projects/RabbitMQ.Client/client/api/IConnection.cs b/projects/RabbitMQ.Client/client/api/IConnection.cs index 4edbe4ebd1..8eac5ef2f3 100644 --- a/projects/RabbitMQ.Client/client/api/IConnection.cs +++ b/projects/RabbitMQ.Client/client/api/IConnection.cs @@ -163,7 +163,7 @@ public interface IConnection : INetworkConnection, IDisposable /// /// This event will never fire for connections that disable automatic recovery. /// - event AsyncEventHandler RecoverySucceeded; + event AsyncEventHandler RecoverySucceededAsync; /// /// Raised when the connection recovery fails, e.g. because reconnection or topology diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs index f4db380a9d..6f17b529d7 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs @@ -206,7 +206,7 @@ await RecoverChannelsAndItsConsumersAsync(recordedEntitiesSemaphoreHeld: true, c ESLog.Info("Connection recovery completed"); ThrowIfDisposed(); - await _recoverySucceededWrapper.InvokeAsync(this, EventArgs.Empty) + await _recoverySucceededAsyncWrapper.InvokeAsync(this, EventArgs.Empty) .ConfigureAwait(false); return true; diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs index 12e3c49324..798c822dff 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs @@ -67,7 +67,7 @@ internal AutorecoveringConnection(ConnectionConfig config, IEndpointResolver end _innerConnection = innerConnection; ConnectionShutdownAsync += HandleConnectionShutdown; - _recoverySucceededWrapper = new AsyncEventingWrapper("OnConnectionRecovery", onExceptionAsync); + _recoverySucceededAsyncWrapper = new AsyncEventingWrapper("OnConnectionRecovery", onExceptionAsync); _connectionRecoveryErrorWrapper = new AsyncEventingWrapper("OnConnectionRecoveryError", onExceptionAsync); _consumerTagChangeAfterRecoveryWrapper = new AsyncEventingWrapper("OnConsumerRecovery", onExceptionAsync); _queueNameChangedAfterRecoveryWrapper = new AsyncEventingWrapper("OnQueueRecovery", onExceptionAsync); @@ -88,12 +88,12 @@ await innerConnection.OpenAsync(cancellationToken) return connection; } - public event AsyncEventHandler RecoverySucceeded + public event AsyncEventHandler RecoverySucceededAsync { - add => _recoverySucceededWrapper.AddHandler(value); - remove => _recoverySucceededWrapper.RemoveHandler(value); + add => _recoverySucceededAsyncWrapper.AddHandler(value); + remove => _recoverySucceededAsyncWrapper.RemoveHandler(value); } - private AsyncEventingWrapper _recoverySucceededWrapper; + private AsyncEventingWrapper _recoverySucceededAsyncWrapper; public event AsyncEventHandler ConnectionRecoveryError { diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index a1a9e24d5b..a7704c329f 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -172,7 +172,7 @@ public event AsyncEventHandler ConnectionShutdownAsync /// /// This event is never fired by non-recovering connections but it is a part of the interface. /// - public event AsyncEventHandler RecoverySucceeded + public event AsyncEventHandler RecoverySucceededAsync { add { } remove { } diff --git a/projects/Test/Common/IntegrationFixture.cs b/projects/Test/Common/IntegrationFixture.cs index 679a86e0d3..5eb37f74ff 100644 --- a/projects/Test/Common/IntegrationFixture.cs +++ b/projects/Test/Common/IntegrationFixture.cs @@ -629,7 +629,7 @@ protected static TaskCompletionSource PrepareForRecovery(IConnection conn) var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); AutorecoveringConnection aconn = conn as AutorecoveringConnection; - aconn.RecoverySucceeded += (source, ea) => + aconn.RecoverySucceededAsync += (source, ea) => { tcs.TrySetResult(true); return Task.CompletedTask; diff --git a/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoverySucceededEventHandlers.cs b/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoverySucceededEventHandlers.cs index 4bd514c694..c6d64fd7c9 100644 --- a/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoverySucceededEventHandlers.cs +++ b/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoverySucceededEventHandlers.cs @@ -47,7 +47,7 @@ public TestRecoverySucceededEventHandlers(ITestOutputHelper output) : base(outpu public async Task TestRecoverySucceededEventHandlers_Called() { int counter = 0; - ((AutorecoveringConnection)_conn).RecoverySucceeded += (source, ea) => + ((AutorecoveringConnection)_conn).RecoverySucceededAsync += (source, ea) => { Interlocked.Increment(ref counter); return Task.CompletedTask; diff --git a/projects/Test/Integration/ConnectionRecovery/TestQueueRecovery.cs b/projects/Test/Integration/ConnectionRecovery/TestQueueRecovery.cs index cd29505d55..60a781fd67 100644 --- a/projects/Test/Integration/ConnectionRecovery/TestQueueRecovery.cs +++ b/projects/Test/Integration/ConnectionRecovery/TestQueueRecovery.cs @@ -76,7 +76,7 @@ public async Task TestServerNamedQueueRecovery() var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var connection = (AutorecoveringConnection)_conn; - connection.RecoverySucceeded += (source, ea) => + connection.RecoverySucceededAsync += (source, ea) => { tcs.SetResult(true); return Task.CompletedTask; diff --git a/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs b/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs index c6b7f8d96c..92905734e2 100644 --- a/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs +++ b/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs @@ -290,7 +290,7 @@ public async Task TestTopologyRecoveryConsumerFilter() using (AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryFilterAsync(filter)) { - conn.RecoverySucceeded += (source, ea) => + conn.RecoverySucceededAsync += (source, ea) => { connectionRecoveryTcs.SetResult(true); return Task.CompletedTask; diff --git a/projects/Test/Integration/TestConnectionTopologyRecovery.cs b/projects/Test/Integration/TestConnectionTopologyRecovery.cs index dcff364a72..00db9e99c9 100644 --- a/projects/Test/Integration/TestConnectionTopologyRecovery.cs +++ b/projects/Test/Integration/TestConnectionTopologyRecovery.cs @@ -96,7 +96,7 @@ public async Task TestTopologyRecoveryQueueFilter() }; AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryFilterAsync(filter); - conn.RecoverySucceeded += (source, ea) => + conn.RecoverySucceededAsync += (source, ea) => { tcs.SetResult(true); return Task.CompletedTask; @@ -146,7 +146,7 @@ public async Task TestTopologyRecoveryExchangeFilter() }; AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryFilterAsync(filter); - conn.RecoverySucceeded += (source, ea) => + conn.RecoverySucceededAsync += (source, ea) => { tcs.SetResult(true); return Task.CompletedTask; @@ -194,7 +194,7 @@ public async Task TestTopologyRecoveryBindingFilter() }; AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryFilterAsync(filter); - conn.RecoverySucceeded += (source, ea) => + conn.RecoverySucceededAsync += (source, ea) => { tcs.SetResult(true); return Task.CompletedTask; @@ -249,7 +249,7 @@ public async Task TestTopologyRecoveryDefaultFilterRecoversAllEntities() var connectionRecoveryTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var filter = new TopologyRecoveryFilter(); AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryFilterAsync(filter); - conn.RecoverySucceeded += (source, ea) => + conn.RecoverySucceededAsync += (source, ea) => { connectionRecoveryTcs.SetResult(true); return Task.CompletedTask; @@ -356,7 +356,7 @@ await channel.QueueDeclareAsync(rq.Name, false, false, false, }; AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryExceptionHandlerAsync(exceptionHandler); - conn.RecoverySucceeded += (source, ea) => + conn.RecoverySucceededAsync += (source, ea) => { tcs.SetResult(true); return Task.CompletedTask; @@ -416,7 +416,7 @@ public async Task TestTopologyRecoveryExchangeExceptionHandler() }; AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryExceptionHandlerAsync(exceptionHandler); - conn.RecoverySucceeded += (source, ea) => + conn.RecoverySucceededAsync += (source, ea) => { tcs.SetResult(true); return Task.CompletedTask; @@ -481,7 +481,7 @@ public async Task TestTopologyRecoveryBindingExceptionHandler() }; AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryExceptionHandlerAsync(exceptionHandler); - conn.RecoverySucceeded += (source, ea) => + conn.RecoverySucceededAsync += (source, ea) => { connectionRecoveryTcs.SetResult(true); return Task.CompletedTask; @@ -547,7 +547,7 @@ public async Task TestTopologyRecoveryConsumerExceptionHandler() }; AutorecoveringConnection conn = await CreateAutorecoveringConnectionWithTopologyRecoveryExceptionHandlerAsync(exceptionHandler); - conn.RecoverySucceeded += (source, ea) => + conn.RecoverySucceededAsync += (source, ea) => { connectionRecoveryTcs.SetResult(true); return Task.CompletedTask; diff --git a/projects/Test/Integration/TestToxiproxy.cs b/projects/Test/Integration/TestToxiproxy.cs index f4f47afb60..8c391424ce 100644 --- a/projects/Test/Integration/TestToxiproxy.cs +++ b/projects/Test/Integration/TestToxiproxy.cs @@ -114,7 +114,7 @@ public async Task TestCloseConnection() return Task.CompletedTask; }; - conn.RecoverySucceeded += (s, ea) => + conn.RecoverySucceededAsync += (s, ea) => { if (IsVerbose) { diff --git a/projects/Test/OAuth2/TestOAuth2.cs b/projects/Test/OAuth2/TestOAuth2.cs index b2bdb1ab92..9df79f0a41 100644 --- a/projects/Test/OAuth2/TestOAuth2.cs +++ b/projects/Test/OAuth2/TestOAuth2.cs @@ -96,7 +96,7 @@ public async Task InitializeAsync() return Task.CompletedTask; }; - _connection.RecoverySucceeded += (sender, ea) => + _connection.RecoverySucceededAsync += (sender, ea) => { _testOutputHelper.WriteLine("{0} [INFO] connection recovery succeeded", DateTime.Now); return Task.CompletedTask; From 2d8bc9a7356b8db1354aec05e83ac8de6cb907ba Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 10:29:29 -0700 Subject: [PATCH 07/18] Rename `ConnectionRecoveryError` to `ConnectionRecoveryErrorAsync` --- projects/RabbitMQ.Client/PublicAPI.Shipped.txt | 2 +- projects/RabbitMQ.Client/client/api/IConnection.cs | 2 +- .../client/impl/AutorecoveringConnection.Recovery.cs | 4 ++-- .../client/impl/AutorecoveringConnection.cs | 10 +++++----- projects/RabbitMQ.Client/client/impl/Connection.cs | 2 +- projects/Test/Common/IntegrationFixture.cs | 2 +- .../Integration/TestConnectionRecoveryWithoutSetup.cs | 2 +- .../Test/Integration/TestConnectionTopologyRecovery.cs | 2 +- projects/Test/Integration/TestToxiproxy.cs | 2 +- projects/Test/OAuth2/TestOAuth2.cs | 2 +- .../SequentialIntegration/TestConnectionRecovery.cs | 2 +- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt index 4210794d56..cd59bc86f0 100644 --- a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt +++ b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt @@ -449,7 +449,6 @@ RabbitMQ.Client.IConnection.ChannelMax.get -> ushort RabbitMQ.Client.IConnection.ClientProperties.get -> System.Collections.Generic.IDictionary RabbitMQ.Client.IConnection.ClientProvidedName.get -> string RabbitMQ.Client.IConnection.CloseReason.get -> RabbitMQ.Client.ShutdownEventArgs -RabbitMQ.Client.IConnection.ConnectionRecoveryError -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.ConnectionUnblocked -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.ConsumerTagChangeAfterRecovery -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.Endpoint.get -> RabbitMQ.Client.AmqpTcpEndpoint @@ -895,3 +894,4 @@ RabbitMQ.Client.IConnection.CallbackExceptionAsync -> RabbitMQ.Client.Events.Asy RabbitMQ.Client.IConnection.ConnectionBlockedAsync -> RabbitMQ.Client.Events.AsyncEventHandler! RabbitMQ.Client.IConnection.ConnectionShutdownAsync -> RabbitMQ.Client.Events.AsyncEventHandler! RabbitMQ.Client.IConnection.RecoverySucceededAsync -> RabbitMQ.Client.Events.AsyncEventHandler! +RabbitMQ.Client.IConnection.ConnectionRecoveryErrorAsync -> RabbitMQ.Client.Events.AsyncEventHandler! diff --git a/projects/RabbitMQ.Client/client/api/IConnection.cs b/projects/RabbitMQ.Client/client/api/IConnection.cs index 8eac5ef2f3..5b5586d2e1 100644 --- a/projects/RabbitMQ.Client/client/api/IConnection.cs +++ b/projects/RabbitMQ.Client/client/api/IConnection.cs @@ -172,7 +172,7 @@ public interface IConnection : INetworkConnection, IDisposable /// /// This event will never fire for connections that disable automatic recovery. /// - event AsyncEventHandler ConnectionRecoveryError; + event AsyncEventHandler ConnectionRecoveryErrorAsync; /// /// Raised when the server-generated tag of a consumer registered on this connection changes during diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs index 6f17b529d7..c269350660 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs @@ -269,10 +269,10 @@ await maybeNewInnerConnection.OpenAsync(cancellationToken) { ESLog.Error("Connection recovery exception.", e); // Trigger recovery error events - if (!_connectionRecoveryErrorWrapper.IsEmpty) + if (!_connectionRecoveryErrorAsyncWrapper.IsEmpty) { // Note: recordedEntities semaphore is _NOT_ held at this point - await _connectionRecoveryErrorWrapper.InvokeAsync(this, new ConnectionRecoveryErrorEventArgs(e)) + await _connectionRecoveryErrorAsyncWrapper.InvokeAsync(this, new ConnectionRecoveryErrorEventArgs(e)) .ConfigureAwait(false); } diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs index 798c822dff..1ca300802f 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs @@ -68,7 +68,7 @@ internal AutorecoveringConnection(ConnectionConfig config, IEndpointResolver end ConnectionShutdownAsync += HandleConnectionShutdown; _recoverySucceededAsyncWrapper = new AsyncEventingWrapper("OnConnectionRecovery", onExceptionAsync); - _connectionRecoveryErrorWrapper = new AsyncEventingWrapper("OnConnectionRecoveryError", onExceptionAsync); + _connectionRecoveryErrorAsyncWrapper = new AsyncEventingWrapper("OnConnectionRecoveryError", onExceptionAsync); _consumerTagChangeAfterRecoveryWrapper = new AsyncEventingWrapper("OnConsumerRecovery", onExceptionAsync); _queueNameChangedAfterRecoveryWrapper = new AsyncEventingWrapper("OnQueueRecovery", onExceptionAsync); @@ -95,12 +95,12 @@ public event AsyncEventHandler RecoverySucceededAsync } private AsyncEventingWrapper _recoverySucceededAsyncWrapper; - public event AsyncEventHandler ConnectionRecoveryError + public event AsyncEventHandler ConnectionRecoveryErrorAsync { - add => _connectionRecoveryErrorWrapper.AddHandler(value); - remove => _connectionRecoveryErrorWrapper.RemoveHandler(value); + add => _connectionRecoveryErrorAsyncWrapper.AddHandler(value); + remove => _connectionRecoveryErrorAsyncWrapper.RemoveHandler(value); } - private AsyncEventingWrapper _connectionRecoveryErrorWrapper; + private AsyncEventingWrapper _connectionRecoveryErrorAsyncWrapper; public event AsyncEventHandler CallbackExceptionAsync { diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index a7704c329f..70b69408c0 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -181,7 +181,7 @@ public event AsyncEventHandler RecoverySucceededAsync /// /// This event is never fired by non-recovering connections but it is a part of the interface. /// - public event AsyncEventHandler ConnectionRecoveryError + public event AsyncEventHandler ConnectionRecoveryErrorAsync { add { } remove { } diff --git a/projects/Test/Common/IntegrationFixture.cs b/projects/Test/Common/IntegrationFixture.cs index 5eb37f74ff..6bb1ce044b 100644 --- a/projects/Test/Common/IntegrationFixture.cs +++ b/projects/Test/Common/IntegrationFixture.cs @@ -225,7 +225,7 @@ protected void AddCallbackExceptionHandlers(IConnection conn, IChannel channel) { if (conn != null) { - conn.ConnectionRecoveryError += (s, ea) => + conn.ConnectionRecoveryErrorAsync += (s, ea) => { _connectionRecoveryException = ea.Exception; diff --git a/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs b/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs index 92905734e2..b4c3264170 100644 --- a/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs +++ b/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs @@ -295,7 +295,7 @@ public async Task TestTopologyRecoveryConsumerFilter() connectionRecoveryTcs.SetResult(true); return Task.CompletedTask; }; - conn.ConnectionRecoveryError += (source, ea) => + conn.ConnectionRecoveryErrorAsync += (source, ea) => { connectionRecoveryTcs.SetException(ea.Exception); return Task.CompletedTask; diff --git a/projects/Test/Integration/TestConnectionTopologyRecovery.cs b/projects/Test/Integration/TestConnectionTopologyRecovery.cs index 00db9e99c9..a499359118 100644 --- a/projects/Test/Integration/TestConnectionTopologyRecovery.cs +++ b/projects/Test/Integration/TestConnectionTopologyRecovery.cs @@ -254,7 +254,7 @@ public async Task TestTopologyRecoveryDefaultFilterRecoversAllEntities() connectionRecoveryTcs.SetResult(true); return Task.CompletedTask; }; - conn.ConnectionRecoveryError += (source, ea) => + conn.ConnectionRecoveryErrorAsync += (source, ea) => { connectionRecoveryTcs.SetException(ea.Exception); return Task.CompletedTask; diff --git a/projects/Test/Integration/TestToxiproxy.cs b/projects/Test/Integration/TestToxiproxy.cs index 8c391424ce..52656c252c 100644 --- a/projects/Test/Integration/TestToxiproxy.cs +++ b/projects/Test/Integration/TestToxiproxy.cs @@ -92,7 +92,7 @@ public async Task TestCloseConnection() return Task.CompletedTask; }; - conn.ConnectionRecoveryError += (s, ea) => + conn.ConnectionRecoveryErrorAsync += (s, ea) => { _output.WriteLine($"[ERROR] connection recovery error {ea.Exception}"); recoverySucceededTcs.SetResult(false); diff --git a/projects/Test/OAuth2/TestOAuth2.cs b/projects/Test/OAuth2/TestOAuth2.cs index 9df79f0a41..5b061ab29d 100644 --- a/projects/Test/OAuth2/TestOAuth2.cs +++ b/projects/Test/OAuth2/TestOAuth2.cs @@ -89,7 +89,7 @@ public async Task InitializeAsync() return Task.CompletedTask; }; - _connection.ConnectionRecoveryError += (sender, ea) => + _connection.ConnectionRecoveryErrorAsync += (sender, ea) => { _testOutputHelper.WriteLine("{0} [ERROR] connection recovery error: {1}", DateTime.Now, ea.Exception); diff --git a/projects/Test/SequentialIntegration/TestConnectionRecovery.cs b/projects/Test/SequentialIntegration/TestConnectionRecovery.cs index ea8c9045ff..a7648906f5 100644 --- a/projects/Test/SequentialIntegration/TestConnectionRecovery.cs +++ b/projects/Test/SequentialIntegration/TestConnectionRecovery.cs @@ -289,7 +289,7 @@ public async Task TestShutdownEventHandlersRecoveryOnConnectionAfterTwoDelayedSe AutorecoveringConnection aconn = (AutorecoveringConnection)_conn; - aconn.ConnectionRecoveryError += (c, args) => + aconn.ConnectionRecoveryErrorAsync += (c, args) => { // Uncomment for debugging // _output.WriteLine("[INFO] ConnectionRecoveryError: {0}", args.Exception); From a48789a16384086de4252e551f5be077f265d8d1 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 10:45:44 -0700 Subject: [PATCH 08/18] Rename `ConsumerTagChangeAfterRecovery` to `ConsumerTagChangeAfterRecoveryAsync` --- projects/RabbitMQ.Client/PublicAPI.Shipped.txt | 2 +- projects/RabbitMQ.Client/client/api/IConnection.cs | 2 +- .../client/impl/AutorecoveringConnection.Recovery.cs | 4 ++-- .../client/impl/AutorecoveringConnection.cs | 10 +++++----- projects/RabbitMQ.Client/client/impl/Connection.cs | 2 +- .../ConnectionRecovery/TestConsumerRecovery.cs | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt index cd59bc86f0..61f8be65eb 100644 --- a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt +++ b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt @@ -450,7 +450,6 @@ RabbitMQ.Client.IConnection.ClientProperties.get -> System.Collections.Generic.I RabbitMQ.Client.IConnection.ClientProvidedName.get -> string RabbitMQ.Client.IConnection.CloseReason.get -> RabbitMQ.Client.ShutdownEventArgs RabbitMQ.Client.IConnection.ConnectionUnblocked -> RabbitMQ.Client.Events.AsyncEventHandler -RabbitMQ.Client.IConnection.ConsumerTagChangeAfterRecovery -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.Endpoint.get -> RabbitMQ.Client.AmqpTcpEndpoint RabbitMQ.Client.IConnection.FrameMax.get -> uint RabbitMQ.Client.IConnection.Heartbeat.get -> System.TimeSpan @@ -895,3 +894,4 @@ RabbitMQ.Client.IConnection.ConnectionBlockedAsync -> RabbitMQ.Client.Events.Asy RabbitMQ.Client.IConnection.ConnectionShutdownAsync -> RabbitMQ.Client.Events.AsyncEventHandler! RabbitMQ.Client.IConnection.RecoverySucceededAsync -> RabbitMQ.Client.Events.AsyncEventHandler! RabbitMQ.Client.IConnection.ConnectionRecoveryErrorAsync -> RabbitMQ.Client.Events.AsyncEventHandler! +RabbitMQ.Client.IConnection.ConsumerTagChangeAfterRecoveryAsync -> RabbitMQ.Client.Events.AsyncEventHandler! diff --git a/projects/RabbitMQ.Client/client/api/IConnection.cs b/projects/RabbitMQ.Client/client/api/IConnection.cs index 5b5586d2e1..76644ea694 100644 --- a/projects/RabbitMQ.Client/client/api/IConnection.cs +++ b/projects/RabbitMQ.Client/client/api/IConnection.cs @@ -182,7 +182,7 @@ public interface IConnection : INetworkConnection, IDisposable /// /// This event will never fire for connections that disable automatic recovery. /// - event AsyncEventHandler ConsumerTagChangeAfterRecovery; + event AsyncEventHandler ConsumerTagChangeAfterRecoveryAsync; /// /// Raised when the name of a server-named queue declared on this connection changes during diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs index c269350660..954e12e7f2 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs @@ -537,12 +537,12 @@ await _recordedEntitiesSemaphore.WaitAsync(cancellationToken) RecordedConsumer consumerWithNewConsumerTag = RecordedConsumer.WithNewConsumerTag(newTag, consumer); UpdateConsumer(oldTag, newTag, consumerWithNewConsumerTag); - if (!_consumerTagChangeAfterRecoveryWrapper.IsEmpty) + if (!_consumerTagChangeAfterRecoveryAsyncWrapper.IsEmpty) { try { _recordedEntitiesSemaphore.Release(); - await _consumerTagChangeAfterRecoveryWrapper.InvokeAsync(this, new ConsumerTagChangedAfterRecoveryEventArgs(oldTag, newTag)) + await _consumerTagChangeAfterRecoveryAsyncWrapper.InvokeAsync(this, new ConsumerTagChangedAfterRecoveryEventArgs(oldTag, newTag)) .ConfigureAwait(false); } finally diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs index 1ca300802f..9d03b4a812 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs @@ -69,7 +69,7 @@ internal AutorecoveringConnection(ConnectionConfig config, IEndpointResolver end ConnectionShutdownAsync += HandleConnectionShutdown; _recoverySucceededAsyncWrapper = new AsyncEventingWrapper("OnConnectionRecovery", onExceptionAsync); _connectionRecoveryErrorAsyncWrapper = new AsyncEventingWrapper("OnConnectionRecoveryError", onExceptionAsync); - _consumerTagChangeAfterRecoveryWrapper = new AsyncEventingWrapper("OnConsumerRecovery", onExceptionAsync); + _consumerTagChangeAfterRecoveryAsyncWrapper = new AsyncEventingWrapper("OnConsumerRecovery", onExceptionAsync); _queueNameChangedAfterRecoveryWrapper = new AsyncEventingWrapper("OnQueueRecovery", onExceptionAsync); Task onExceptionAsync(Exception exception, string context) => @@ -126,12 +126,12 @@ public event AsyncEventHandler ConnectionUnblocked remove => InnerConnection.ConnectionUnblocked -= value; } - public event AsyncEventHandler ConsumerTagChangeAfterRecovery + public event AsyncEventHandler ConsumerTagChangeAfterRecoveryAsync { - add => _consumerTagChangeAfterRecoveryWrapper.AddHandler(value); - remove => _consumerTagChangeAfterRecoveryWrapper.RemoveHandler(value); + add => _consumerTagChangeAfterRecoveryAsyncWrapper.AddHandler(value); + remove => _consumerTagChangeAfterRecoveryAsyncWrapper.RemoveHandler(value); } - private AsyncEventingWrapper _consumerTagChangeAfterRecoveryWrapper; + private AsyncEventingWrapper _consumerTagChangeAfterRecoveryAsyncWrapper; public event AsyncEventHandler QueueNameChangedAfterRecovery { diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index 70b69408c0..a9941741d0 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -190,7 +190,7 @@ public event AsyncEventHandler ConnectionRecov /// /// This event is never fired by non-recovering connections but it is a part of the interface. /// - public event AsyncEventHandler ConsumerTagChangeAfterRecovery + public event AsyncEventHandler ConsumerTagChangeAfterRecoveryAsync { add { } remove { } diff --git a/projects/Test/Integration/ConnectionRecovery/TestConsumerRecovery.cs b/projects/Test/Integration/ConnectionRecovery/TestConsumerRecovery.cs index aa79ce6e3b..4f627cfc87 100644 --- a/projects/Test/Integration/ConnectionRecovery/TestConsumerRecovery.cs +++ b/projects/Test/Integration/ConnectionRecovery/TestConsumerRecovery.cs @@ -58,7 +58,7 @@ public async Task TestConsumerRecoveryWithManyConsumers() } var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - ((AutorecoveringConnection)_conn).ConsumerTagChangeAfterRecovery += (prev, current) => + ((AutorecoveringConnection)_conn).ConsumerTagChangeAfterRecoveryAsync += (prev, current) => { tcs.TrySetResult(true); return Task.CompletedTask; From a4ebfc2c16a8ec92a105a3344f33c714238f73cb Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 10:47:26 -0700 Subject: [PATCH 09/18] Rename `QueueNameChangedAfterRecovery` to `QueueNameChangedAfterRecoveryAsync` --- projects/RabbitMQ.Client/PublicAPI.Shipped.txt | 2 +- projects/RabbitMQ.Client/client/api/IConnection.cs | 2 +- .../client/impl/AutorecoveringConnection.Recovery.cs | 4 ++-- .../client/impl/AutorecoveringConnection.cs | 10 +++++----- projects/RabbitMQ.Client/client/impl/Connection.cs | 2 +- .../ConnectionRecovery/TestQueueRecovery.cs | 2 +- .../Integration/TestConnectionRecoveryWithoutSetup.cs | 4 ++-- .../SequentialIntegration/TestConnectionRecovery.cs | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt index 61f8be65eb..0c9f06d946 100644 --- a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt +++ b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt @@ -455,7 +455,6 @@ RabbitMQ.Client.IConnection.FrameMax.get -> uint RabbitMQ.Client.IConnection.Heartbeat.get -> System.TimeSpan RabbitMQ.Client.IConnection.IsOpen.get -> bool RabbitMQ.Client.IConnection.Protocol.get -> RabbitMQ.Client.IProtocol -RabbitMQ.Client.IConnection.QueueNameChangedAfterRecovery -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.RecoveringConsumer -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.ServerProperties.get -> System.Collections.Generic.IDictionary RabbitMQ.Client.IConnection.ShutdownReport.get -> System.Collections.Generic.IEnumerable @@ -895,3 +894,4 @@ RabbitMQ.Client.IConnection.ConnectionShutdownAsync -> RabbitMQ.Client.Events.As RabbitMQ.Client.IConnection.RecoverySucceededAsync -> RabbitMQ.Client.Events.AsyncEventHandler! RabbitMQ.Client.IConnection.ConnectionRecoveryErrorAsync -> RabbitMQ.Client.Events.AsyncEventHandler! RabbitMQ.Client.IConnection.ConsumerTagChangeAfterRecoveryAsync -> RabbitMQ.Client.Events.AsyncEventHandler! +RabbitMQ.Client.IConnection.QueueNameChangedAfterRecoveryAsync -> RabbitMQ.Client.Events.AsyncEventHandler! diff --git a/projects/RabbitMQ.Client/client/api/IConnection.cs b/projects/RabbitMQ.Client/client/api/IConnection.cs index 76644ea694..79b8de7ceb 100644 --- a/projects/RabbitMQ.Client/client/api/IConnection.cs +++ b/projects/RabbitMQ.Client/client/api/IConnection.cs @@ -192,7 +192,7 @@ public interface IConnection : INetworkConnection, IDisposable /// /// This event will never fire for connections that disable automatic recovery. /// - event AsyncEventHandler QueueNameChangedAfterRecovery; + event AsyncEventHandler QueueNameChangedAfterRecoveryAsync; /// /// Raised when a consumer is about to be recovered. This event raises when topology recovery diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs index 954e12e7f2..d49ea664fb 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs @@ -381,12 +381,12 @@ await RecordQueueAsync(new RecordedQueue(newName, recordedQueue), recordedEntitiesSemaphoreHeld: recordedEntitiesSemaphoreHeld, cancellationToken) .ConfigureAwait(false); - if (!_queueNameChangedAfterRecoveryWrapper.IsEmpty) + if (!_queueNameChangedAfterRecoveryAsyncWrapper.IsEmpty) { try { _recordedEntitiesSemaphore.Release(); - await _queueNameChangedAfterRecoveryWrapper.InvokeAsync(this, new QueueNameChangedAfterRecoveryEventArgs(oldName, newName)) + await _queueNameChangedAfterRecoveryAsyncWrapper.InvokeAsync(this, new QueueNameChangedAfterRecoveryEventArgs(oldName, newName)) .ConfigureAwait(false); } finally diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs index 9d03b4a812..6159fe4cd2 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs @@ -70,7 +70,7 @@ internal AutorecoveringConnection(ConnectionConfig config, IEndpointResolver end _recoverySucceededAsyncWrapper = new AsyncEventingWrapper("OnConnectionRecovery", onExceptionAsync); _connectionRecoveryErrorAsyncWrapper = new AsyncEventingWrapper("OnConnectionRecoveryError", onExceptionAsync); _consumerTagChangeAfterRecoveryAsyncWrapper = new AsyncEventingWrapper("OnConsumerRecovery", onExceptionAsync); - _queueNameChangedAfterRecoveryWrapper = new AsyncEventingWrapper("OnQueueRecovery", onExceptionAsync); + _queueNameChangedAfterRecoveryAsyncWrapper = new AsyncEventingWrapper("OnQueueRecovery", onExceptionAsync); Task onExceptionAsync(Exception exception, string context) => _innerConnection.OnCallbackExceptionAsync(CallbackExceptionEventArgs.Build(exception, context)); @@ -133,12 +133,12 @@ public event AsyncEventHandler Consume } private AsyncEventingWrapper _consumerTagChangeAfterRecoveryAsyncWrapper; - public event AsyncEventHandler QueueNameChangedAfterRecovery + public event AsyncEventHandler QueueNameChangedAfterRecoveryAsync { - add => _queueNameChangedAfterRecoveryWrapper.AddHandler(value); - remove => _queueNameChangedAfterRecoveryWrapper.RemoveHandler(value); + add => _queueNameChangedAfterRecoveryAsyncWrapper.AddHandler(value); + remove => _queueNameChangedAfterRecoveryAsyncWrapper.RemoveHandler(value); } - private AsyncEventingWrapper _queueNameChangedAfterRecoveryWrapper; + private AsyncEventingWrapper _queueNameChangedAfterRecoveryAsyncWrapper; public event AsyncEventHandler RecoveringConsumer { diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index a9941741d0..c7c3a23f86 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -199,7 +199,7 @@ public event AsyncEventHandler Consume /// /// This event is never fired by non-recovering connections but it is a part of the interface. /// - public event AsyncEventHandler QueueNameChangedAfterRecovery + public event AsyncEventHandler QueueNameChangedAfterRecoveryAsync { add { } remove { } diff --git a/projects/Test/Integration/ConnectionRecovery/TestQueueRecovery.cs b/projects/Test/Integration/ConnectionRecovery/TestQueueRecovery.cs index 60a781fd67..dd21340be8 100644 --- a/projects/Test/Integration/ConnectionRecovery/TestQueueRecovery.cs +++ b/projects/Test/Integration/ConnectionRecovery/TestQueueRecovery.cs @@ -81,7 +81,7 @@ public async Task TestServerNamedQueueRecovery() tcs.SetResult(true); return Task.CompletedTask; }; - connection.QueueNameChangedAfterRecovery += (source, ea) => + connection.QueueNameChangedAfterRecoveryAsync += (source, ea) => { nameAfter = ea.NameAfter; return Task.CompletedTask; diff --git a/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs b/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs index b4c3264170..33afd22884 100644 --- a/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs +++ b/projects/Test/Integration/TestConnectionRecoveryWithoutSetup.cs @@ -167,7 +167,7 @@ public async Task TestConsumerRecoveryOnClientNamedQueueWithOneRecovery() await AssertConsumerCountAsync(ch, q1, 1); bool queueNameChangeAfterRecoveryCalled = false; - c.QueueNameChangedAfterRecovery += (source, ea) => + c.QueueNameChangedAfterRecoveryAsync += (source, ea) => { queueNameChangeAfterRecoveryCalled = true; return Task.CompletedTask; @@ -226,7 +226,7 @@ public async Task TestConsumerRecoveryWithServerNamedQueue() bool queueNameBeforeIsEqual = false; bool queueNameChangeAfterRecoveryCalled = false; string qnameAfterRecovery = null; - c.QueueNameChangedAfterRecovery += (source, ea) => + c.QueueNameChangedAfterRecoveryAsync += (source, ea) => { queueNameChangeAfterRecoveryCalled = true; queueNameBeforeIsEqual = qname.Equals(ea.NameBefore); diff --git a/projects/Test/SequentialIntegration/TestConnectionRecovery.cs b/projects/Test/SequentialIntegration/TestConnectionRecovery.cs index a7648906f5..17eafeafa4 100644 --- a/projects/Test/SequentialIntegration/TestConnectionRecovery.cs +++ b/projects/Test/SequentialIntegration/TestConnectionRecovery.cs @@ -223,7 +223,7 @@ public async Task TestServerNamedTransientAutoDeleteQueueAndBindingRecovery() string nameAfter = null; var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - ((AutorecoveringConnection)_conn).QueueNameChangedAfterRecovery += (source, ea) => + ((AutorecoveringConnection)_conn).QueueNameChangedAfterRecoveryAsync += (source, ea) => { nameBefore = ea.NameBefore; nameAfter = ea.NameAfter; From 4af30b06f8ac9c350bd8a1f29872b59f920e0bdf Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 10:48:49 -0700 Subject: [PATCH 10/18] Rename `RecoveringConsumer` to `RecoveringConsumerAsync` --- projects/RabbitMQ.Client/PublicAPI.Shipped.txt | 2 +- projects/RabbitMQ.Client/client/api/IConnection.cs | 2 +- .../client/impl/AutorecoveringConnection.Recovery.cs | 2 +- .../client/impl/AutorecoveringConnection.cs | 8 ++++---- projects/RabbitMQ.Client/client/impl/Connection.cs | 2 +- .../Connection/TestRecoveringConsumerEventHandlers.cs | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt index 0c9f06d946..9906e55c39 100644 --- a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt +++ b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt @@ -455,7 +455,6 @@ RabbitMQ.Client.IConnection.FrameMax.get -> uint RabbitMQ.Client.IConnection.Heartbeat.get -> System.TimeSpan RabbitMQ.Client.IConnection.IsOpen.get -> bool RabbitMQ.Client.IConnection.Protocol.get -> RabbitMQ.Client.IProtocol -RabbitMQ.Client.IConnection.RecoveringConsumer -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.ServerProperties.get -> System.Collections.Generic.IDictionary RabbitMQ.Client.IConnection.ShutdownReport.get -> System.Collections.Generic.IEnumerable RabbitMQ.Client.IConnectionExtensions @@ -895,3 +894,4 @@ RabbitMQ.Client.IConnection.RecoverySucceededAsync -> RabbitMQ.Client.Events.Asy RabbitMQ.Client.IConnection.ConnectionRecoveryErrorAsync -> RabbitMQ.Client.Events.AsyncEventHandler! RabbitMQ.Client.IConnection.ConsumerTagChangeAfterRecoveryAsync -> RabbitMQ.Client.Events.AsyncEventHandler! RabbitMQ.Client.IConnection.QueueNameChangedAfterRecoveryAsync -> RabbitMQ.Client.Events.AsyncEventHandler! +RabbitMQ.Client.IConnection.RecoveringConsumerAsync -> RabbitMQ.Client.Events.AsyncEventHandler! diff --git a/projects/RabbitMQ.Client/client/api/IConnection.cs b/projects/RabbitMQ.Client/client/api/IConnection.cs index 79b8de7ceb..6643e442e2 100644 --- a/projects/RabbitMQ.Client/client/api/IConnection.cs +++ b/projects/RabbitMQ.Client/client/api/IConnection.cs @@ -204,7 +204,7 @@ public interface IConnection : INetworkConnection, IDisposable /// /// This event will never fire for connections that disable automatic recovery. /// - public event AsyncEventHandler RecoveringConsumer; + public event AsyncEventHandler RecoveringConsumerAsync; event AsyncEventHandler ConnectionUnblocked; diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs index d49ea664fb..d47b35a98a 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs @@ -520,7 +520,7 @@ internal async ValueTask RecoverConsumersAsync(AutorecoveringChannel channelToRe try { _recordedEntitiesSemaphore.Release(); - await _consumerAboutToBeRecoveredWrapper.InvokeAsync(this, new RecoveringConsumerEventArgs(consumer.ConsumerTag, consumer.Arguments)) + await _recoveringConsumerAsyncWrapper.InvokeAsync(this, new RecoveringConsumerEventArgs(consumer.ConsumerTag, consumer.Arguments)) .ConfigureAwait(false); } finally diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs index 6159fe4cd2..9949cf0ba9 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs @@ -140,12 +140,12 @@ public event AsyncEventHandler QueueName } private AsyncEventingWrapper _queueNameChangedAfterRecoveryAsyncWrapper; - public event AsyncEventHandler RecoveringConsumer + public event AsyncEventHandler RecoveringConsumerAsync { - add => _consumerAboutToBeRecoveredWrapper.AddHandler(value); - remove => _consumerAboutToBeRecoveredWrapper.RemoveHandler(value); + add => _recoveringConsumerAsyncWrapper.AddHandler(value); + remove => _recoveringConsumerAsyncWrapper.RemoveHandler(value); } - private AsyncEventingWrapper _consumerAboutToBeRecoveredWrapper; + private AsyncEventingWrapper _recoveringConsumerAsyncWrapper; public string? ClientProvidedName => _config.ClientProvidedName; diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index c7c3a23f86..842310c481 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -139,7 +139,7 @@ public event AsyncEventHandler ConnectionUnblocked } private AsyncEventingWrapper _connectionUnblockedWrapper; - public event AsyncEventHandler RecoveringConsumer + public event AsyncEventHandler RecoveringConsumerAsync { add => _consumerAboutToBeRecoveredWrapper.AddHandler(value); remove => _consumerAboutToBeRecoveredWrapper.RemoveHandler(value); diff --git a/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoveringConsumerEventHandlers.cs b/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoveringConsumerEventHandlers.cs index 919b1c35b2..2146370438 100644 --- a/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoveringConsumerEventHandlers.cs +++ b/projects/Test/Integration/ConnectionRecovery/EventHandlerRecovery/Connection/TestRecoveringConsumerEventHandlers.cs @@ -56,7 +56,7 @@ public async Task TestRecoveringConsumerEventHandlers_Called(int iterations) await _channel.BasicConsumeAsync(q, true, cons); int counter = 0; - ((AutorecoveringConnection)_conn).RecoveringConsumer += (sender, args) => + ((AutorecoveringConnection)_conn).RecoveringConsumerAsync += (sender, args) => { Interlocked.Increment(ref counter); return Task.CompletedTask; @@ -88,7 +88,7 @@ public async Task TestRecoveringConsumerEventHandler_EventArgumentsArePassedDown bool ctagMatches = false; bool consumerArgumentMatches = false; - ((AutorecoveringConnection)_conn).RecoveringConsumer += (sender, args) => + ((AutorecoveringConnection)_conn).RecoveringConsumerAsync += (sender, args) => { // We cannot assert here because NUnit throws when an assertion fails. This exception is caught and // passed to a CallbackExceptionHandler, instead of failing the test. Instead, we have to do this trick From 90159437c83f4455a4e0e4c1841bccfa7239acfe Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 10:51:26 -0700 Subject: [PATCH 11/18] Ensure that `_recoveringConsumerAsyncWrapper` is initialized as expected. --- .../client/impl/AutorecoveringConnection.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs index 9949cf0ba9..e9d8c3b953 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs @@ -67,10 +67,21 @@ internal AutorecoveringConnection(ConnectionConfig config, IEndpointResolver end _innerConnection = innerConnection; ConnectionShutdownAsync += HandleConnectionShutdown; - _recoverySucceededAsyncWrapper = new AsyncEventingWrapper("OnConnectionRecovery", onExceptionAsync); - _connectionRecoveryErrorAsyncWrapper = new AsyncEventingWrapper("OnConnectionRecoveryError", onExceptionAsync); - _consumerTagChangeAfterRecoveryAsyncWrapper = new AsyncEventingWrapper("OnConsumerRecovery", onExceptionAsync); - _queueNameChangedAfterRecoveryAsyncWrapper = new AsyncEventingWrapper("OnQueueRecovery", onExceptionAsync); + + _recoverySucceededAsyncWrapper = + new AsyncEventingWrapper("OnConnectionRecovery", onExceptionAsync); + + _connectionRecoveryErrorAsyncWrapper = + new AsyncEventingWrapper("OnConnectionRecoveryError", onExceptionAsync); + + _consumerTagChangeAfterRecoveryAsyncWrapper = + new AsyncEventingWrapper("OnConsumerRecovery", onExceptionAsync); + + _queueNameChangedAfterRecoveryAsyncWrapper = + new AsyncEventingWrapper("OnQueueRecovery", onExceptionAsync); + + _recoveringConsumerAsyncWrapper = + new AsyncEventingWrapper("OnRecoveringConsumer", onExceptionAsync); Task onExceptionAsync(Exception exception, string context) => _innerConnection.OnCallbackExceptionAsync(CallbackExceptionEventArgs.Build(exception, context)); From 31e9ccc383343c1aa75a51ee2d18f4fbca9d6c15 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 10:54:26 -0700 Subject: [PATCH 12/18] Rename `ConnectionUnblocked` to `ConnectionUnblockedAsync` --- .../RabbitMQ.Client/PublicAPI.Shipped.txt | 2 +- .../RabbitMQ.Client/client/api/IConnection.cs | 12 ++++++--- .../client/impl/AutorecoveringConnection.cs | 6 ++--- .../client/impl/Connection.Commands.cs | 4 +-- .../RabbitMQ.Client/client/impl/Connection.cs | 26 ++++++++++++------- .../TestConnectionBlocked.cs | 2 +- .../TestConnectionBlockedChannelLeak.cs | 2 +- .../TestConnectionRecovery.cs | 2 +- 8 files changed, 35 insertions(+), 21 deletions(-) diff --git a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt index 9906e55c39..d8b36cd5bf 100644 --- a/projects/RabbitMQ.Client/PublicAPI.Shipped.txt +++ b/projects/RabbitMQ.Client/PublicAPI.Shipped.txt @@ -449,7 +449,6 @@ RabbitMQ.Client.IConnection.ChannelMax.get -> ushort RabbitMQ.Client.IConnection.ClientProperties.get -> System.Collections.Generic.IDictionary RabbitMQ.Client.IConnection.ClientProvidedName.get -> string RabbitMQ.Client.IConnection.CloseReason.get -> RabbitMQ.Client.ShutdownEventArgs -RabbitMQ.Client.IConnection.ConnectionUnblocked -> RabbitMQ.Client.Events.AsyncEventHandler RabbitMQ.Client.IConnection.Endpoint.get -> RabbitMQ.Client.AmqpTcpEndpoint RabbitMQ.Client.IConnection.FrameMax.get -> uint RabbitMQ.Client.IConnection.Heartbeat.get -> System.TimeSpan @@ -895,3 +894,4 @@ RabbitMQ.Client.IConnection.ConnectionRecoveryErrorAsync -> RabbitMQ.Client.Even RabbitMQ.Client.IConnection.ConsumerTagChangeAfterRecoveryAsync -> RabbitMQ.Client.Events.AsyncEventHandler! RabbitMQ.Client.IConnection.QueueNameChangedAfterRecoveryAsync -> RabbitMQ.Client.Events.AsyncEventHandler! RabbitMQ.Client.IConnection.RecoveringConsumerAsync -> RabbitMQ.Client.Events.AsyncEventHandler! +RabbitMQ.Client.IConnection.ConnectionUnblockedAsync -> RabbitMQ.Client.Events.AsyncEventHandler! diff --git a/projects/RabbitMQ.Client/client/api/IConnection.cs b/projects/RabbitMQ.Client/client/api/IConnection.cs index 6643e442e2..3ea28ac77c 100644 --- a/projects/RabbitMQ.Client/client/api/IConnection.cs +++ b/projects/RabbitMQ.Client/client/api/IConnection.cs @@ -145,8 +145,6 @@ public interface IConnection : INetworkConnection, IDisposable /// event AsyncEventHandler CallbackExceptionAsync; - event AsyncEventHandler ConnectionBlockedAsync; - /// /// Raised when the connection is destroyed. /// @@ -206,7 +204,15 @@ public interface IConnection : INetworkConnection, IDisposable /// public event AsyncEventHandler RecoveringConsumerAsync; - event AsyncEventHandler ConnectionUnblocked; + /// + /// Raised when a connection is blocked by the AMQP broker. + /// + event AsyncEventHandler ConnectionBlockedAsync; + + /// + /// Raised when a connection is unblocked by the AMQP broker. + /// + event AsyncEventHandler ConnectionUnblockedAsync; /// /// This method updates the secret used to authenticate this connection. diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs index e9d8c3b953..a1131b2164 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs @@ -131,10 +131,10 @@ public event AsyncEventHandler ConnectionShutdownAsync remove => InnerConnection.ConnectionShutdownAsync -= value; } - public event AsyncEventHandler ConnectionUnblocked + public event AsyncEventHandler ConnectionUnblockedAsync { - add => InnerConnection.ConnectionUnblocked += value; - remove => InnerConnection.ConnectionUnblocked -= value; + add => InnerConnection.ConnectionUnblockedAsync += value; + remove => InnerConnection.ConnectionUnblockedAsync -= value; } public event AsyncEventHandler ConsumerTagChangeAfterRecoveryAsync diff --git a/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs b/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs index bef6a12587..0a954b89eb 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs @@ -65,9 +65,9 @@ internal Task HandleConnectionBlockedAsync(string reason) internal Task HandleConnectionUnblockedAsync() { - if (!_connectionUnblockedWrapper.IsEmpty) + if (!_connectionUnblockedAsyncWrapper.IsEmpty) { - return _connectionUnblockedWrapper.InvokeAsync(this, EventArgs.Empty); + return _connectionUnblockedAsyncWrapper.InvokeAsync(this, EventArgs.Empty); } return Task.CompletedTask; } diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index 842310c481..7f76e0ba24 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -65,10 +65,18 @@ internal Connection(ConnectionConfig config, IFrameHandler frameHandler) _frameHandler = frameHandler; Func onException = (exception, context) => OnCallbackExceptionAsync(CallbackExceptionEventArgs.Build(exception, context)); - _callbackExceptionAsyncWrapper = new AsyncEventingWrapper(string.Empty, (exception, context) => Task.CompletedTask); - _connectionBlockedAsyncWrapper = new AsyncEventingWrapper("OnConnectionBlocked", onException); - _connectionUnblockedWrapper = new AsyncEventingWrapper("OnConnectionUnblocked", onException); - _connectionShutdownAsyncWrapper = new AsyncEventingWrapper("OnShutdown", onException); + + _callbackExceptionAsyncWrapper = + new AsyncEventingWrapper(string.Empty, (exception, context) => Task.CompletedTask); + + _connectionBlockedAsyncWrapper = + new AsyncEventingWrapper("OnConnectionBlocked", onException); + + _connectionUnblockedAsyncWrapper = + new AsyncEventingWrapper("OnConnectionUnblocked", onException); + + _connectionShutdownAsyncWrapper = + new AsyncEventingWrapper("OnShutdown", onException); _sessionManager = new SessionManager(this, 0, config.MaxInboundMessageBodySize); _session0 = new MainSession(this, config.MaxInboundMessageBodySize); @@ -132,12 +140,12 @@ public event AsyncEventHandler ConnectionBlockedAsyn } private AsyncEventingWrapper _connectionBlockedAsyncWrapper; - public event AsyncEventHandler ConnectionUnblocked + public event AsyncEventHandler ConnectionUnblockedAsync { - add => _connectionUnblockedWrapper.AddHandler(value); - remove => _connectionUnblockedWrapper.RemoveHandler(value); + add => _connectionUnblockedAsyncWrapper.AddHandler(value); + remove => _connectionUnblockedAsyncWrapper.RemoveHandler(value); } - private AsyncEventingWrapper _connectionUnblockedWrapper; + private AsyncEventingWrapper _connectionUnblockedAsyncWrapper; public event AsyncEventHandler RecoveringConsumerAsync { @@ -209,7 +217,7 @@ internal void TakeOver(Connection other) { _callbackExceptionAsyncWrapper.Takeover(other._callbackExceptionAsyncWrapper); _connectionBlockedAsyncWrapper.Takeover(other._connectionBlockedAsyncWrapper); - _connectionUnblockedWrapper.Takeover(other._connectionUnblockedWrapper); + _connectionUnblockedAsyncWrapper.Takeover(other._connectionUnblockedAsyncWrapper); _connectionShutdownAsyncWrapper.Takeover(other._connectionShutdownAsyncWrapper); // TODO Why are other wrappers not taken over? } diff --git a/projects/Test/SequentialIntegration/TestConnectionBlocked.cs b/projects/Test/SequentialIntegration/TestConnectionBlocked.cs index 18d8160612..c610da4542 100644 --- a/projects/Test/SequentialIntegration/TestConnectionBlocked.cs +++ b/projects/Test/SequentialIntegration/TestConnectionBlocked.cs @@ -66,7 +66,7 @@ public async Task TestConnectionBlockedNotification() await UnblockAsync(); }; - _conn.ConnectionUnblocked += (object sender, EventArgs ea) => + _conn.ConnectionUnblockedAsync += (object sender, EventArgs ea) => { tcs.SetResult(true); return Task.CompletedTask; diff --git a/projects/Test/SequentialIntegration/TestConnectionBlockedChannelLeak.cs b/projects/Test/SequentialIntegration/TestConnectionBlockedChannelLeak.cs index a08f5256fd..daeab8ab3b 100644 --- a/projects/Test/SequentialIntegration/TestConnectionBlockedChannelLeak.cs +++ b/projects/Test/SequentialIntegration/TestConnectionBlockedChannelLeak.cs @@ -88,7 +88,7 @@ public async Task TestConnectionBlockedChannelLeak_GH1573() return Task.CompletedTask; }; - _conn.ConnectionUnblocked += (object sender, EventArgs ea) => + _conn.ConnectionUnblockedAsync += (object sender, EventArgs ea) => { connectionUnblockedTcs.SetResult(true); return Task.CompletedTask; diff --git a/projects/Test/SequentialIntegration/TestConnectionRecovery.cs b/projects/Test/SequentialIntegration/TestConnectionRecovery.cs index 17eafeafa4..dc1831a7b0 100644 --- a/projects/Test/SequentialIntegration/TestConnectionRecovery.cs +++ b/projects/Test/SequentialIntegration/TestConnectionRecovery.cs @@ -336,7 +336,7 @@ public async Task TestShutdownEventHandlersRecoveryOnConnectionAfterTwoDelayedSe public async Task TestUnblockedListenersRecovery() { var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - _conn.ConnectionUnblocked += (source, ea) => + _conn.ConnectionUnblockedAsync += (source, ea) => { tcs.SetResult(true); return Task.CompletedTask; From b82ae276835e08b9d6f18326c121e2c5957fb9d5 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 13:10:21 -0700 Subject: [PATCH 13/18] Rename `HandleMainLoopException` to `HandleMainLoopExceptionAsync` --- .../client/impl/Connection.Heartbeat.cs | 2 +- .../client/impl/Connection.Receive.cs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/projects/RabbitMQ.Client/client/impl/Connection.Heartbeat.cs b/projects/RabbitMQ.Client/client/impl/Connection.Heartbeat.cs index 56aec1897f..881d7c2c46 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.Heartbeat.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.Heartbeat.cs @@ -108,7 +108,7 @@ private async void HeartbeatReadTimerCallback(object? state) { var eose = new EndOfStreamException($"Heartbeat missing with heartbeat == {_heartbeat} seconds"); LogCloseError(eose.Message, eose); - await HandleMainLoopException(new ShutdownEventArgs(ShutdownInitiator.Library, 0, "End of stream", eose)) + await HandleMainLoopExceptionAsync(new ShutdownEventArgs(ShutdownInitiator.Library, 0, "End of stream", eose)) .ConfigureAwait(false); shouldTerminate = true; } diff --git a/projects/RabbitMQ.Client/client/impl/Connection.Receive.cs b/projects/RabbitMQ.Client/client/impl/Connection.Receive.cs index 8e69e84949..d9285b1b41 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.Receive.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.Receive.cs @@ -62,7 +62,7 @@ await ReceiveLoopAsync(mainLoopToken) Constants.InternalError, "Thread aborted (AppDomain unloaded?)", exception: taex); - await HandleMainLoopException(ea) + await HandleMainLoopExceptionAsync(ea) .ConfigureAwait(false); } #endif @@ -73,7 +73,7 @@ await HandleMainLoopException(ea) 0, "End of stream", exception: eose); - await HandleMainLoopException(ea) + await HandleMainLoopExceptionAsync(ea) .ConfigureAwait(false); } catch (HardProtocolException hpe) @@ -91,7 +91,7 @@ await HardProtocolExceptionHandlerAsync(hpe, mainLoopToken) Constants.InternalError, fileLoadException.Message, exception: fileLoadException); - await HandleMainLoopException(ea) + await HandleMainLoopExceptionAsync(ea) .ConfigureAwait(false); } catch (OperationCanceledException ocex) @@ -106,7 +106,7 @@ await HandleMainLoopException(ea) Constants.InternalError, ocex.Message, exception: ocex); - await HandleMainLoopException(ea) + await HandleMainLoopExceptionAsync(ea) .ConfigureAwait(false); } } @@ -116,7 +116,7 @@ await HandleMainLoopException(ea) Constants.InternalError, ex.Message, exception: ex); - await HandleMainLoopException(ea) + await HandleMainLoopExceptionAsync(ea) .ConfigureAwait(false); } @@ -207,7 +207,7 @@ private void MaybeTerminateMainloopAndStopHeartbeatTimers(bool cancelMainLoop = MaybeStopHeartbeatTimers(); } - private async Task HandleMainLoopException(ShutdownEventArgs reason) + private async Task HandleMainLoopExceptionAsync(ShutdownEventArgs reason) { string message = reason.GetLogMessage(); if (false == SetCloseReason(reason)) From 275134e19b8e7e83c2ff093c2cacb0b4a4544c44 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 13:11:32 -0700 Subject: [PATCH 14/18] Rename `HandleConnectionShutdown` to `HandleConnectionShutdownAsync` --- .../client/impl/AutorecoveringConnection.Recovery.cs | 2 +- .../RabbitMQ.Client/client/impl/AutorecoveringConnection.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs index d47b35a98a..0ffd5773d0 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs @@ -46,7 +46,7 @@ internal sealed partial class AutorecoveringConnection private Task? _recoveryTask; private readonly CancellationTokenSource _recoveryCancellationTokenSource = new CancellationTokenSource(); - private Task HandleConnectionShutdown(object? _, ShutdownEventArgs args) + private Task HandleConnectionShutdownAsync(object? _, ShutdownEventArgs args) { if (ShouldTriggerConnectionRecovery(args)) { diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs index a1131b2164..c7315eaf4b 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs @@ -66,7 +66,7 @@ internal AutorecoveringConnection(ConnectionConfig config, IEndpointResolver end _endpoints = endpoints; _innerConnection = innerConnection; - ConnectionShutdownAsync += HandleConnectionShutdown; + ConnectionShutdownAsync += HandleConnectionShutdownAsync; _recoverySucceededAsyncWrapper = new AsyncEventingWrapper("OnConnectionRecovery", onExceptionAsync); From 213f0da604cfb6b3514740295f6487a817e5d40c Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 13:13:42 -0700 Subject: [PATCH 15/18] Rename `ClosedViaPeer` to `ClosedViaPeerAsync` Rename `OnShutdown` to `OnShutdownAsync` --- projects/RabbitMQ.Client/client/impl/ChannelBase.cs | 2 +- .../RabbitMQ.Client/client/impl/Connection.Receive.cs | 4 ++-- projects/RabbitMQ.Client/client/impl/Connection.cs | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/projects/RabbitMQ.Client/client/impl/ChannelBase.cs b/projects/RabbitMQ.Client/client/impl/ChannelBase.cs index 5ef55ed28d..fa2daead4b 100644 --- a/projects/RabbitMQ.Client/client/impl/ChannelBase.cs +++ b/projects/RabbitMQ.Client/client/impl/ChannelBase.cs @@ -715,7 +715,7 @@ protected async Task HandleConnectionCloseAsync(IncomingCommand cmd, Cance var reason = new ShutdownEventArgs(ShutdownInitiator.Peer, method._replyCode, method._replyText, method._classId, method._methodId); try { - await Session.Connection.ClosedViaPeer(reason) + await Session.Connection.ClosedViaPeerAsync(reason) .ConfigureAwait(false); var replyMethod = new ConnectionCloseOk(); diff --git a/projects/RabbitMQ.Client/client/impl/Connection.Receive.cs b/projects/RabbitMQ.Client/client/impl/Connection.Receive.cs index d9285b1b41..f9ecbd918e 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.Receive.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.Receive.cs @@ -218,7 +218,7 @@ private async Task HandleMainLoopExceptionAsync(ShutdownEventArgs reason) _channel0.MaybeSetConnectionStartException(reason.Exception!); - await OnShutdown(reason).ConfigureAwait(false); + await OnShutdownAsync(reason).ConfigureAwait(false); LogCloseError($"unexpected connection closure: {message}", reason.Exception!); } @@ -227,7 +227,7 @@ private async Task HardProtocolExceptionHandlerAsync(HardProtocolException hpe, { if (SetCloseReason(hpe.ShutdownReason)) { - await OnShutdown(hpe.ShutdownReason).ConfigureAwait(false); + await OnShutdownAsync(hpe.ShutdownReason).ConfigureAwait(false); await _session0.SetSessionClosingAsync(false) .ConfigureAwait(false); try diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index 7f76e0ba24..bcc68e9e01 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -328,7 +328,7 @@ internal async Task CloseAsync(ShutdownEventArgs reason, bool abort, TimeSpan ti { cancellationToken.ThrowIfCancellationRequested(); - await OnShutdown(reason) + await OnShutdownAsync(reason) .ConfigureAwait(false); await _session0.SetSessionClosingAsync(false) .ConfigureAwait(false); @@ -409,7 +409,7 @@ await _frameHandler.CloseAsync(cancellationToken) } } - internal async Task ClosedViaPeer(ShutdownEventArgs reason) + internal async Task ClosedViaPeerAsync(ShutdownEventArgs reason) { if (false == SetCloseReason(reason)) { @@ -420,7 +420,7 @@ internal async Task ClosedViaPeer(ShutdownEventArgs reason) // We are quiescing, but still allow for server-close } - await OnShutdown(reason) + await OnShutdownAsync(reason) .ConfigureAwait(false); await _session0.SetSessionClosingAsync(true) .ConfigureAwait(false); @@ -441,7 +441,7 @@ private async Task FinishCloseAsync(CancellationToken cancellationToken) } ///Broadcasts notification of the final shutdown of the connection. - private Task OnShutdown(ShutdownEventArgs reason) + private Task OnShutdownAsync(ShutdownEventArgs reason) { ThrowIfDisposed(); return _connectionShutdownAsyncWrapper.InvokeAsync(this, reason); From 5d97fa1db1247bd9cd987370587e4deae5f94187 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 13:17:20 -0700 Subject: [PATCH 16/18] Rename `onException` to `onExceptionAsync` --- projects/RabbitMQ.Client/client/impl/Connection.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index bcc68e9e01..009daa1a29 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -64,19 +64,18 @@ internal Connection(ConnectionConfig config, IFrameHandler frameHandler) _config = config; _frameHandler = frameHandler; - Func onException = (exception, context) => OnCallbackExceptionAsync(CallbackExceptionEventArgs.Build(exception, context)); - _callbackExceptionAsyncWrapper = - new AsyncEventingWrapper(string.Empty, (exception, context) => Task.CompletedTask); + new AsyncEventingWrapper(string.Empty, + (exception, context) => Task.CompletedTask); _connectionBlockedAsyncWrapper = - new AsyncEventingWrapper("OnConnectionBlocked", onException); + new AsyncEventingWrapper("OnConnectionBlocked", onExceptionAsync); _connectionUnblockedAsyncWrapper = - new AsyncEventingWrapper("OnConnectionUnblocked", onException); + new AsyncEventingWrapper("OnConnectionUnblocked", onExceptionAsync); _connectionShutdownAsyncWrapper = - new AsyncEventingWrapper("OnShutdown", onException); + new AsyncEventingWrapper("OnShutdown", onExceptionAsync); _sessionManager = new SessionManager(this, 0, config.MaxInboundMessageBodySize); _session0 = new MainSession(this, config.MaxInboundMessageBodySize); @@ -89,6 +88,9 @@ internal Connection(ConnectionConfig config, IFrameHandler frameHandler) }; _mainLoopTask = Task.CompletedTask; + + Task onExceptionAsync(Exception exception, string context) => + OnCallbackExceptionAsync(CallbackExceptionEventArgs.Build(exception, context)); } public Guid Id => _id; From 1deeae3a959ff1e0c6baf73cdc9a8f03f2115b35 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 13:24:58 -0700 Subject: [PATCH 17/18] Add `_consumerAboutToBeRecoveredAsyncWrapper` to `TakeOver` --- projects/RabbitMQ.Client/client/impl/Connection.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index 009daa1a29..4c184cf255 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -151,10 +151,10 @@ public event AsyncEventHandler ConnectionUnblockedAsync public event AsyncEventHandler RecoveringConsumerAsync { - add => _consumerAboutToBeRecoveredWrapper.AddHandler(value); - remove => _consumerAboutToBeRecoveredWrapper.RemoveHandler(value); + add => _consumerAboutToBeRecoveredAsyncWrapper.AddHandler(value); + remove => _consumerAboutToBeRecoveredAsyncWrapper.RemoveHandler(value); } - private AsyncEventingWrapper _consumerAboutToBeRecoveredWrapper; + private AsyncEventingWrapper _consumerAboutToBeRecoveredAsyncWrapper; public event AsyncEventHandler ConnectionShutdownAsync { @@ -221,7 +221,7 @@ internal void TakeOver(Connection other) _connectionBlockedAsyncWrapper.Takeover(other._connectionBlockedAsyncWrapper); _connectionUnblockedAsyncWrapper.Takeover(other._connectionUnblockedAsyncWrapper); _connectionShutdownAsyncWrapper.Takeover(other._connectionShutdownAsyncWrapper); - // TODO Why are other wrappers not taken over? + _consumerAboutToBeRecoveredAsyncWrapper.Takeover(other._consumerAboutToBeRecoveredAsyncWrapper); } internal async ValueTask OpenAsync(CancellationToken cancellationToken) From 5b6956b45756d82a995408704105d6f13a6d56ab Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 17 Sep 2024 13:42:13 -0700 Subject: [PATCH 18/18] Remove unused `virtual` keyword. --- projects/RabbitMQ.Client/client/impl/SessionBase.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/RabbitMQ.Client/client/impl/SessionBase.cs b/projects/RabbitMQ.Client/client/impl/SessionBase.cs index 77c970da2e..672b9d5277 100644 --- a/projects/RabbitMQ.Client/client/impl/SessionBase.cs +++ b/projects/RabbitMQ.Client/client/impl/SessionBase.cs @@ -86,13 +86,13 @@ public event EventHandler SessionShutdown [MemberNotNullWhen(false, nameof(CloseReason))] public bool IsOpen => CloseReason is null; - public virtual Task OnConnectionShutdownAsync(object? conn, ShutdownEventArgs reason) + public Task OnConnectionShutdownAsync(object? conn, ShutdownEventArgs reason) { Close(reason); return Task.CompletedTask; } - public virtual void OnSessionShutdown(ShutdownEventArgs reason) + public void OnSessionShutdown(ShutdownEventArgs reason) { Connection.ConnectionShutdownAsync -= OnConnectionShutdownAsync; _sessionShutdownWrapper.Invoke(this, reason);