-1

I created an Azure Durable Function in Python using the consumption plan. The function receives an ID and then basically reads some SQL database and do some webscrap. Then, it writes stuff in the SQL and send an e-mail.

I call the function around 2000 times in a period of 1 hour everyday using POST method. I do it 2000 times because I have 2000 ID's that need to be treated by this function.

After I run, around 10% of the calls will not succeed. Thus, I will retry the function untill all of the 2000 entries treated for that day.

This process works fine for one or two weeks.. But then, it stops working at all.

In Azure Storage Explorer I can see several instances with a status of eternal "pending".

After deleting both instance and history tables, and running again, it will eventually succeed.

The error that I'm getting is this:

Any thoughts?

 Exception while executing function: Functions.DouMonitorHttpStart ---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException : Result: Failure Exception: TypeError: unable to encode outgoing TypedData: unsupported type '<class 'azure.functions.http.HttpResponseConverter'>' for Python type 'coroutine' Stack:   File '/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py', line 427, in _handle__invocation_request     return_value = bindings.to_outgoing_proto(   File '/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/bindings/meta.py', line 116, in to_outgoing_proto     datum = get_datum(binding, obj, pytype)   File '/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/bindings/meta.py', line 107, in get_datum     raise TypeError(     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at async Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.InvokeCore(Object[] parameters,FunctionInvocationContext context) at /src/azure-functions-host/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs : 96    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at async Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) at /src/azure-functions-host/src/WebJobs.Script/Description/FunctionInvokerBase.cs : 82    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at async Microsoft.Azure.WebJobs.Script.Description.FunctionGenerator.Coerce[T](Task`1 src) at /src/azure-functions-host/src/WebJobs.Script/Description/FunctionGenerator.cs : 225    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at async Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync[TReflected,TReturnValue](Object instance,Object[] arguments) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs : 52    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync(IFunctionInvoker invoker,ParameterHelper parameterHelper,CancellationTokenSource timeoutTokenSource,CancellationTokenSource functionCancellationTokenSource,Boolean throwOnTimeout,TimeSpan timerInterval,IFunctionInstance instance) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs : 582    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance,ParameterHelper parameterHelper,ILogger logger,CancellationTokenSource functionCancellationTokenSource) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs : 528    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance,FunctionStartedMessage message,FunctionInstanceLogEntry instanceLogEntry,ParameterHelper parameterHelper,ILogger logger,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs : 307    End of inner exception    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance,FunctionStartedMessage message,FunctionInstanceLogEntry instanceLogEntry,ParameterHelper parameterHelper,ILogger logger,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs : 353    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs : 108

I think the problem is that I need to purge the instance history. Not sure how to do it besides deleting the table.

I also think that the function will have some kind of cold start, which means that the first ~10% calls will always not succeed.

Thanks!

  • I would personally recommend just switching to aws or gcp, sounds like azure is too much headache so not worth it. – rv.kvetch May 26 '22 at 02:06

1 Answers1

0
TypeError: unable to encode outgoing TypedData: unsupported type '<class 'azure.functions.http.HttpResponseConverter'>' for Python type 'coroutine' Stack:   File '/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py

In the case of HTTP trigger, the function annotation indicates that you must return a HttpResponse object rather than a None. If you anticipate that your http client will not receive any content, use return func.HttpResponse("", status code=200) instead.


I also think that the function will have some kind of cold start, which means that the first ~10% calls will always not succeed.

Yes, If the Azure Functions hosted in Consumption Plan, then Cold Start behavior occurs. To avoid that, better to migrate for the App Service Plan or Premium hosting plan.


I think the problem is that I need to purge the instance history. Not sure how to do it besides deleting the table.

Yes! You Should perform the periodic clean-up operation manually by calling the Purge instance History method in Python.

Note: Purge an entity only after it has been idle (i.e., has not performed any operations) for at least 30 minutes.

  • Thanks a lot! Do you know where I can find a course of Azure Functions with Python? There is a lot of infrastructure stuff that I really can't understand... – PandasBots May 26 '22 at 11:55
  • Please refer to this [official documentation](https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Cazurecli-linux%2Capplication-level) –  May 26 '22 at 12:04