Azure / azure-functions-durable-extension

Durable Task Framework extension for Azure Functions
MIT License
711 stars 263 forks source link

[out-of-proc] `RetryContext.LastFailure` incorrectly captures thrown exception #2711

Closed Ilia-Kosenkov closed 3 months ago

Ilia-Kosenkov commented 5 months ago

Description

When inspecting RetryContext.LastFailure during activity retry cycle, I noticed that .ErrorType and .ErrorMessage are populated from Exception.Message, with .ErrorType being the first part of .Message, until a ':', while the remaining part of the .Message is copied to .ErrorMessage.

As a result of this, RetryContext.LastFailure.IsCausedBy<TException>() does not work, because it relies on .ErrorType, which is malformed.

If I drop ':' from my exception message, then .ErrorType is "(unknown)"

Expected behavior

Actual behavior

Relevant source code snippets

Had to scramble some info here. Here is the exception I throw from my activity:

Screenshot 2024-01-08 141740

And here is what I observe in the AsyncRetryHandler:

Screenshot 2024-01-08 141810

Known workarounds

I originally intended to append Reason: ... to exception messages as a workaround, but this lead me to discovery that ':' is treated specially (which made things even worse). I am considering (ab-)using this feature to simulate the intended behavior.

App Details

Ilia-Kosenkov commented 5 months ago

I believe now it is a duplicate (or rather 'caused by') #2697. Please verify and close if it is so.

davidmrdavid commented 5 months ago

I agree the issues are related - we're looking to reconsider how we're treating inner exception handling in .NET isolated. Let me close this so we can use the issue you linked as the 'aggregate' ticket. Thanks

cgillum commented 3 months ago

Reactivating since this issue is broader than #2697. Specifically, 2697 only covers the correctness of IsCausedBy<T>() when we have the expected exception information available to us. This issue covers the case where the Durable extension receives unexpected exception information.