Skip to content

Commit 7fa6c1e

Browse files
author
Vlad Ionescu
committed
adding handler for DomainUnload event in connection's main loop
1 parent 1b12580 commit 7fa6c1e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

projects/client/RabbitMQ.Client/src/client/impl/ConnectionBase.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ public void NotifyHeartbeatThread()
578578

579579
public void MainLoop()
580580
{
581+
Thread.GetDomain().DomainUnload += new EventHandler(HandleDomainUnload);
582+
581583
bool shutdownCleanly = false;
582584
try
583585
{
@@ -682,7 +684,18 @@ public void FinishClose()
682684
m_model0.SetCloseReason(m_closeReason);
683685
m_model0.FinishClose();
684686
}
685-
687+
688+
/// <remarks>
689+
/// We need to close the socket, otherwise attempting to unload the domain
690+
/// could cause a CannotUnloadAppDomainException
691+
/// </remarks>
692+
public void HandleDomainUnload(object sender, EventArgs ea)
693+
{
694+
HandleMainLoopException(new ShutdownEventArgs(ShutdownInitiator.Library,
695+
CommonFraming.Constants.InternalError,
696+
"Domain Unload"));
697+
}
698+
686699
public bool HardProtocolExceptionHandler(HardProtocolException hpe)
687700
{
688701
if (SetCloseReason(hpe.ShutdownReason))

0 commit comments

Comments
 (0)