Azure / azure-functions-durable-extension

Durable Task Framework extension for Azure Functions
MIT License
715 stars 271 forks source link

CsvHelper FieldValidationException & Orchestrator throws StackOverflowException #550

Open juchom opened 5 years ago

juchom commented 5 years ago

I'm parsing a csv file with CsvHelper with bad data in it.

I have a StackOverflowException

[19-Dec-18 14:06:32] Executing 'Activity' (Reason='', Id=18c5e63e-6798-484c-b08d-2a304b110168) [19-Dec-18 14:06:32] Bad date [19-Dec-18 14:06:32] Anonymously Hosted DynamicMethods Assembly: Exception of type 'CsvHelper.FieldValidationException' was thrown. [19-Dec-18 14:06:32] Executed 'Activity' (Failed, Id=18c5e63e-6798-484c-b08d-2a304b110168) [19-Dec-18 14:06:32] System.Private.CoreLib: Exception while executing function: Activity. Anonymously Hosted DynamicMethods Assembly: Exception of type 'CsvHelper.FieldValidationException' was thrown. [19-Dec-18 14:06:32] da62c5035f914ffbb221f22953279497: Function 'Activity (Activity)' failed with an error. Reason: CsvHelper.FieldValidationException: Exception of type 'CsvHelper.FieldValidationException' was thrown. [19-Dec-18 14:06:32] at lambda_method(Closure ) [19-Dec-18 14:06:32] at CsvHelper.Expressions.RecordCreator.Create[T]() [19-Dec-18 14:06:32] at CsvHelper.Expressions.RecordManager.Create[T]() [19-Dec-18 14:06:32] at CsvHelper.CsvReader.GetRecords[T]()+MoveNext() [19-Dec-18 14:06:32] at System.Collections.Generic.List1.AddEnumerable(IEnumerable1 enumerable) [19-Dec-18 14:06:32] at System.Collections.Generic.List1..ctor(IEnumerable1 collection) [19-Dec-18 14:06:32] at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) [19-Dec-18 14:06:32] at SOE.Activity.Run(Object obj, ILogger log) in C:\dev [soe.zip](https://github.com/Azure/azure-functions-durable-extension/files/2695153/soe.zip) \soe\SOE\Activity.cs:line 22 [19-Dec-18 14:06:32] at Microsoft.Azure.WebJobs.Host.Executors.VoidTaskMethodInvoker2.InvokeAsync(TReflected instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\VoidTaskMethodInvoker.cs:line 20 [19-Dec-18 14:06:32] at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 63 [19-Dec-18 14:06:32] at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 556 [19-Dec-18 14:06:32] at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstance instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 503 [19-Dec-18 14:06:32] at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstance instance, ParameterHelper parameterHelper, IFunctionOutputDefinition outputDefinition, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 439 [19-Dec-18 14:06:32] at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstance instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 249. IsReplay: False. State: Failed. HubName: DurableFunctionsHub. AppName: . SlotName: . ExtensionVersion: 1.7.0. SequenceNumber: 7. [19-Dec-18 14:06:32] Host lock lease acquired by instance ID '0000000000000000000000009EA34753'. Process is terminating due to StackOverflowException. Press any key to continue . . .

You have a simple project attached to reproduce the issue.

soe.zip

cgillum commented 5 years ago

Thanks for this report and for the reference project. I was able to reproduce the issue. It looks like a bug in our exception serialization code.

cgillum commented 5 years ago

The problem is FieldValidationException. It's a complex data structure and the Json.NET serializer we use runs into a StackOverflowException when trying to serialize instances of this object. I imagine there are other object and/or exception types which may cause similar problems.

StackOverflowException cannot be caught, so we'll need to find another way to deal with this.