Skip to content

Commit 0f2f247

Browse files
authored
Merge pull request #1781 from rabbitmq/rabbitmq-dotnet-client-1777
Fix #1777
2 parents 17b216d + e33544d commit 0f2f247

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
@@ -795,13 +795,18 @@ protected async Task<bool> HandleConnectionCloseAsync(IncomingCommand cmd, Cance
795795
var reason = new ShutdownEventArgs(ShutdownInitiator.Peer, method._replyCode, method._replyText, method._classId, method._methodId);
796796
try
797797
{
798-
await Session.Connection.ClosedViaPeerAsync(reason, cancellationToken)
799-
.ConfigureAwait(false);
800-
798+
/*
799+
* rabbitmq-dotnet-client#1777
800+
* Send the connection.close-ok message prior to closing within the client,
801+
* because ClosedViaPeerAsync will stop the main loop
802+
*/
801803
var replyMethod = new ConnectionCloseOk();
802804
await ModelSendAsync(in replyMethod, cancellationToken)
803805
.ConfigureAwait(false);
804806

807+
await Session.Connection.ClosedViaPeerAsync(reason, cancellationToken)
808+
.ConfigureAwait(false);
809+
805810
SetCloseReason(Session.Connection.CloseReason!);
806811
}
807812
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)