Skip to content

Commit 817f38d

Browse files
committed
Attempting to restart a new Rabbit MQ Channel anytime there's a channel callback exception. Closes GH-1977
1 parent 2f4558c commit 817f38d

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/Transports/RabbitMQ/Wolverine.RabbitMQ/Internal/RabbitMqChannelAgent.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,36 @@ protected async Task startNewChannel()
6868

6969
Channel.CallbackExceptionAsync += (sender, args) =>
7070
{
71-
Logger.LogError(args.Exception, "Callback error in Rabbit Mq agent");
71+
Logger.LogError(args.Exception, "Callback error in Rabbit Mq agent. Attempting to restart the channel");
72+
73+
// Try to restart the connection
74+
#pragma warning disable VSTHRD110
75+
Task.Run(async () =>
76+
#pragma warning restore VSTHRD110
77+
{
78+
await Locker.WaitAsync();
79+
try
80+
{
81+
_monitor.Remove(this);
82+
try
83+
{
84+
await teardownChannel();
85+
}
86+
catch (Exception e)
87+
{
88+
Logger.LogError(e, "Error when trying to tear down a blocked channel");
89+
}
90+
91+
Channel = null;
92+
await EnsureInitiated();
93+
Logger.LogInformation("Restarted the Rabbit MQ channel");
94+
}
95+
finally
96+
{
97+
Locker.Release();
98+
}
99+
});
100+
72101
return Task.CompletedTask;
73102
};
74103

0 commit comments

Comments
 (0)