Skip to content

Commit

Permalink
Port #1494 to main
Browse files Browse the repository at this point in the history
Fixes #1493 by porting 55010ab to `main`
  • Loading branch information
lukebakken committed Feb 12, 2024
1 parent 1d5b36a commit e42fe53
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
22 changes: 20 additions & 2 deletions projects/RabbitMQ.Client/client/api/ShutdownEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,32 @@ public Exception Exception
/// Override ToString to be useful for debugging.
/// </summary>
public override string ToString()
{
return GetMessageCore()
+ (_exception != null ? $", exception={_exception}" : string.Empty);
}

/// <summary>
/// Gets a message suitable for logging.
/// </summary>
/// <remarks>
/// This leaves out the full exception ToString since logging will include it separately.
/// </remarks>
internal string GetLogMessage()
{
return GetMessageCore()
+ (_exception != null ? $", exception={_exception.Message}" : string.Empty);
}

private string GetMessageCore()
{
return $"AMQP close-reason, initiated by {Initiator}"
+ $", code={ReplyCode}"
+ (ReplyText != null ? $", text='{ReplyText}'" : string.Empty)
+ $", classId={ClassId}"
+ $", methodId={MethodId}"
+ (Cause != null ? $", cause={Cause}" : string.Empty)
+ (_exception != null ? $", exception={_exception}" : string.Empty);
+ (Cause != null ? $", cause={Cause}" : string.Empty);
}

}
}
5 changes: 3 additions & 2 deletions projects/RabbitMQ.Client/client/impl/Connection.Receive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,17 @@ private void TerminateMainloop()

private void HandleMainLoopException(ShutdownEventArgs reason)
{
string message = reason.GetLogMessage();
if (!SetCloseReason(reason))
{
LogCloseError($"Unexpected Main Loop Exception while closing: {reason}", reason.Exception);
LogCloseError($"Unexpected Main Loop Exception while closing: {message}", reason.Exception);
return;
}

_channel0.MaybeSetConnectionStartException(reason.Exception);

OnShutdown(reason);
LogCloseError($"Unexpected connection closure: {reason}", reason.Exception);
LogCloseError($"Unexpected connection closure: {message}", reason.Exception);
}

private async Task HardProtocolExceptionHandlerAsync(HardProtocolException hpe, CancellationToken cancellationToken)
Expand Down

0 comments on commit e42fe53

Please sign in to comment.