Skip to content

Commit

Permalink
Handle AppDomain unload
Browse files Browse the repository at this point in the history
Fixes #826
  • Loading branch information
lukebakken committed May 30, 2024
1 parent 6135e35 commit e12c1c9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,23 @@ static bool ShouldTriggerConnectionRecovery(ShutdownEventArgs args)
}
}

// happens when EOF is reached, e.g. due to RabbitMQ node
// connectivity loss or abrupt shutdown
if (args.Initiator == ShutdownInitiator.Library)
{
return true;
/*
* https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/826
* Happens when an AppDomain is unloaded
*/
if (args.Exception is ThreadAbortException &&
args.ReplyCode == Constants.InternalError)
{
return false;
}
else
{
// happens when EOF is reached, e.g. due to RabbitMQ node
// connectivity loss or abrupt shutdown
return true;
}
}

return false;
Expand Down
13 changes: 13 additions & 0 deletions projects/RabbitMQ.Client/client/impl/Connection.Receive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ private async Task MainLoop()
await ReceiveLoopAsync(mainLoopToken)
.ConfigureAwait(false);
}
#if NETSTANDARD
catch (ThreadAbortException taex)
{
/*
* https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/826
*/
var ea = new ShutdownEventArgs(ShutdownInitiator.Library,
Constants.InternalError,
"Thread aborted (AppDomain unloaded?)",
exception: taex);
HandleMainLoopException(ea);
}
#endif
catch (EndOfStreamException eose)
{
// Possible heartbeat exception
Expand Down

0 comments on commit e12c1c9

Please sign in to comment.