Skip to content

Commit e33544d

Browse files
committed
Fix #1777
Fixes #1777 * Adds a test that requires `PossibleAuthenticationFailureException` when attempting to log into RabbitMQ using invalid credentials. * Fix the issue by calling `ClosedViaPeerAsync` _after_ sending the `connection.close-ok` response to the broker.
1 parent 5f4621f commit e33544d

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

projects/RabbitMQ.Client/Impl/Channel.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -793,13 +793,18 @@ protected async Task<bool> HandleConnectionCloseAsync(IncomingCommand cmd, Cance
793793
var reason = new ShutdownEventArgs(ShutdownInitiator.Peer, method._replyCode, method._replyText, method._classId, method._methodId);
794794
try
795795
{
796-
await Session.Connection.ClosedViaPeerAsync(reason, cancellationToken)
797-
.ConfigureAwait(false);
798-
796+
/*
797+
* rabbitmq-dotnet-client#1777
798+
* Send the connection.close-ok message prior to closing within the client,
799+
* because ClosedViaPeerAsync will stop the main loop
800+
*/
799801
var replyMethod = new ConnectionCloseOk();
800802
await ModelSendAsync(in replyMethod, cancellationToken)
801803
.ConfigureAwait(false);
802804

805+
await Session.Connection.ClosedViaPeerAsync(reason, cancellationToken)
806+
.ConfigureAwait(false);
807+
803808
SetCloseReason(Session.Connection.CloseReason!);
804809
}
805810
catch (IOException)

projects/Test/Integration/GH/TestGitHubIssues.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
using System.Threading.Tasks;
3535
using RabbitMQ.Client;
3636
using RabbitMQ.Client.Events;
37+
using RabbitMQ.Client.Exceptions;
3738
using Xunit;
3839
using Xunit.Abstractions;
3940

@@ -147,5 +148,22 @@ public async Task DisposeWhileCatchingTimeoutDeadlocksRepro_GH1759()
147148

148149
await _conn.DisposeAsync();
149150
}
151+
152+
[Fact]
153+
public async Task InvalidCredentialsShouldThrow_GH1777()
154+
{
155+
string userPass = Guid.NewGuid().ToString();
156+
157+
_connFactory = new ConnectionFactory
158+
{
159+
UserName = userPass,
160+
Password = userPass
161+
};
162+
163+
BrokerUnreachableException ex =
164+
await Assert.ThrowsAnyAsync<BrokerUnreachableException>(
165+
async () => await _connFactory.CreateConnectionAsync());
166+
Assert.IsAssignableFrom<PossibleAuthenticationFailureException>(ex.InnerException);
167+
}
150168
}
151169
}

0 commit comments

Comments
 (0)