I have an Azure Function with a service bus trigger:
public static async Task Run([ServiceBusTrigger(
"%inputTopicName%",
"%subscriptionName%",
AccessRights.Manage,
Connection = "connection")]string mySbMsg)
In 99.9% of the invocations, the trigger successfully resolves to a subscription on Azure Service Bus. But sometimes, I see the following error in my log:
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: UptimeChecker ---> System.ArgumentException: The argument connectionString is null or white space.
Parameter name: connectionString
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.FunctionInvocationFilterInvoker.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__16.MoveNext()
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__13.MoveNext()
It seems that the service bus trigger cannot resolve the connection
variable from settings.
I tried to add a debugging filter to my function, in order to find out what is going on:
public class DebuggingFilter : FunctionInvocationFilterAttribute
{
public override Task OnExecutingAsync(FunctionExecutingContext executingContext, CancellationToken cancellationToken)
{
executingContext.Properties.Add("connection", ConfigurationManager.AppSettings["connection"]);
executingContext.Properties.Add("inputTopicName", ConfigurationManager.AppSettings["inputTopicName"]);
executingContext.Properties.Add("subscriptionName", ConfigurationManager.AppSettings["subscriptionName"]);
return base.OnExecutingAsync(executingContext, cancellationToken);
}
}
When an error is logged in my function, the properties added to FunctionExecutionContext
are automatically added to the log message. The weird thing here is that in the scenario where Azure Functions throw this exception, the property values are resolved and shown in the log message.
What could be the cause of this? I've experienced multiple problems with resolving settings from Azure Functions, so maybe it's a general problem?
Get connection informationSign in to the Azure portal. Select SQL Databases from the left-hand menu, and select your database on the SQL databases page. Select Connection strings under Settings and copy the complete ADO.NET connection string. For Azure SQL Managed Instance copy connection string for public endpoint.
Open Queue. Select Service Bus Explorer (preview) under Settings. Write policy name and select the checkbox to listen and click Create. Select the policy name and copy Primary or Secondary Connection String.
I don't have a final answer to this question, but I do want to share some details with other people experiencing the same problem. The problem seems to be isolated to v1 consumption based functions only. After upgrading my function to Azure Functions v2 and utilizing the new configuration system available there, I no longer experience the problem above. Since v1 is no longer the current version, I do not want to spend more time debugging into this, when v2 seems to be working.
According to this: you should be using the latest version 2.3.0 for nuget Microsoft.Azure.WebJobs.ServiceBus -Version 2.3.0
I would also check if it is an issue when running in consumption plan by hardcoding the connection to see if it is an issue reading the configuration of connection. And otherwise test it on app service plan.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With