Azure/azure-functions-rabbitmq-extension

RabbitMQTrigger throwing AlreadyClosedException

arthur-conde opened this issue · 1 comments

We have a few functions running inside an isolated .NET 6 function app on the v4 runtime, all triggered by listening to messages from RabbitMQ.

After upgrading to the most recent version of the extension, we have started seeing AlreadyClosedException thrown from the extension.

RabbitMQ.Client.Exceptions.AlreadyClosedException:
   at RabbitMQ.Client.Impl.SessionBase.Transmit (RabbitMQ.Client, Version=6.0.0.0, Culture=neutral, PublicKeyToken=89e7d7c5feba84ce)
   at RabbitMQ.Client.Framing.Impl.Model._Private_QueueDeclare (RabbitMQ.Client, Version=6.0.0.0, Culture=neutral, PublicKeyToken=89e7d7c5feba84ce)
   at RabbitMQ.Client.Impl.ModelBase.QueueDeclare (RabbitMQ.Client, Version=6.0.0.0, Culture=neutral, PublicKeyToken=89e7d7c5feba84ce)
   at RabbitMQ.Client.Impl.AutorecoveringModel.QueueDeclarePassive (RabbitMQ.Client, Version=6.0.0.0, Culture=neutral, PublicKeyToken=89e7d7c5feba84ce)
   at Microsoft.Azure.WebJobs.Extensions.RabbitMQ.RabbitMQModel.QueueDeclarePassive (Microsoft.Azure.WebJobs.Extensions.RabbitMQ, Version=2.0.3.0, Culture=neutral, PublicKeyToken=null: /_/extension/WebJobs.Extensions.RabbitMQ/Trigger/RabbitMQModel.cs:26)
   at Microsoft.Azure.WebJobs.Extensions.RabbitMQ.RabbitMQListener.GetMetricsAsync (Microsoft.Azure.WebJobs.Extensions.RabbitMQ, Version=2.0.3.0, Culture=neutral, PublicKeyToken=null: /_/extension/WebJobs.Extensions.RabbitMQ/Trigger/RabbitMQListener.cs:156)
   at Microsoft.Azure.WebJobs.Extensions.RabbitMQ.RabbitMQListener+<Microsoft-Azure-WebJobs-Host-Scale-IScaleMonitor-GetMetricsAsync>d__21.MoveNext (Microsoft.Azure.WebJobs.Extensions.RabbitMQ, Version=2.0.3.0, Culture=neutral, PublicKeyToken=null)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.Azure.WebJobs.Script.Scale.FunctionsScaleMonitorService+<TakeMetricsSamplesAsync>d__13.MoveNext (Microsoft.Azure.WebJobs.Script, Version=4.17.0.0, Culture=neutral, PublicKeyToken=null: /_/src/WebJobs.Script/Scale/FunctionsScaleMonitorService.cs:95)

I'm not sure what is causing this to occur. Each function uses three queues: a queue the function is bound to, a retry queue that uses expire and dead letter set to the first, and a dead letter queue that stores messages that failed to process.

An example of such a function follows:

[Function("Webhooks")]
public async Task WebhookFunctionAsync([RabbitMQTrigger("%Queues:Webhook%", ConnectionStringSetting = "Queues:Uri")] string message, FunctionContext context)
{
   // Work done here
}

How do I prevent this exception from getting thrown?