Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeSpan Parameters Cannot be Deserialized for Activities #199

Closed
wsugarman opened this issue Sep 25, 2023 · 3 comments
Closed

TimeSpan Parameters Cannot be Deserialized for Activities #199

wsugarman opened this issue Sep 25, 2023 · 3 comments
Labels
P1 Reliability Durable functions get stuck or don’t run as expected.

Comments

@wsugarman
Copy link
Member

Repro: Sandbox.Functions.Worker.zip

I created a simple orchestration and activity, which I've attached, that passes a TimeSpan parameter. The orchestration is able to deserialize the value, but the activity throws an error:

[2023-09-25T19:08:33.116Z] Function 'EchoTimeSpanAsync', Invocation id '53fbfc18-c746-4d37-9fe6-723d025830bc': An exception was thrown by the invocation.
[2023-09-25T19:08:33.117Z] Result: Function 'EchoTimeSpanAsync', Invocation id '53fbfc18-c746-4d37-9fe6-723d025830bc': An exception was thrown by the invocation.
Exception: Microsoft.Azure.Functions.Worker.FunctionInputConverterException: Error converting 1 input parameters for Function 'EchoTimeSpanAsync': Cannot convert input parameter 'value' to type 'System.TimeSpan' from type 'System.String'. Error:System.Text.Json.JsonException: Invalid leading zero before '0'. Path: $ | LineNumber: 0 | BytePositionInLine: 1.
[2023-09-25T19:08:33.118Z]  ---> System.Text.Json.JsonReaderException: Invalid leading zero before '0'. LineNumber: 0 | BytePositionInLine: 1.
[2023-09-25T19:08:33.119Z]    at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
[2023-09-25T19:08:33.120Z]    at System.Text.Json.Utf8JsonReader.ConsumeZero(ReadOnlySpan`1& data, Int32& i)
[2023-09-25T19:08:33.121Z]    at System.Text.Json.Utf8JsonReader.TryGetNumber(ReadOnlySpan`1 data, Int32& consumed)
[2023-09-25T19:08:33.122Z]    at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first)
[2023-09-25T19:08:33.123Z]    at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
[2023-09-25T19:08:33.124Z]    at System.Text.Json.Utf8JsonReader.Read()
[2023-09-25T19:08:33.125Z]    at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
[2023-09-25T19:08:33.126Z]    --- End of inner exception stack trace ---
[2023-09-25T19:08:33.127Z]    at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)
[2023-09-25T19:08:33.127Z] Executed 'Functions.EchoTimeSpanAsync' (Failed, Id=53fbfc18-c746-4d37-9fe6-723d025830bc, Duration=68ms)
[2023-09-25T19:08:33.128Z]    at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
[2023-09-25T19:08:33.130Z] System.Private.CoreLib: Exception while executing function: Functions.EchoTimeSpanAsync. System.Private.CoreLib: Result: Failure

The message makes it sound like the value was serialized as a standard string (E.g. 00:01:00) while the deserializer expects JSON (E.g. "00:01:00").

Additionally, after failing the logs report the function invocation as having succeeded, while the DTFx reports the correct status of "Failed".

[2023-09-25T19:08:33.288Z] Executing 'Functions.EchoAsync' (Reason='(null)', Id=bbf776c1-e485-4dbf-97bd-fb2ae333208a)
[2023-09-25T19:08:33.414Z] Executed 'Functions.EchoAsync' (Succeeded, Id=bbf776c1-e485-4dbf-97bd-fb2ae333208a, Duration=128ms)

This same behavior occurs in versions 1.0.0, 1.0.2, and 1.0.3 of the package Microsoft.Azure.Functions.Worker.Extensions.DurableTask.

@lilyjma lilyjma added P1 Reliability Durable functions get stuck or don’t run as expected. and removed Needs: Triage 🔍 labels Sep 26, 2023
@jviau
Copy link
Member

jviau commented Oct 3, 2023

I have traced the issue down to how the WebJobs extension decides to serialize data to the worker. In the case of TimeSpan and other types which serialize to a JSON value type (ie: not an object { }), there is this code which this scenario falls into.

The end result is we erroneously unwrap the JSON input and send across as a strong. For TimeSpan we end up stripping the containing quotes from it.

@jviau
Copy link
Member

jviau commented Oct 3, 2023

Possibly related: Azure/azure-functions-durable-extension#2504

@jviau
Copy link
Member

jviau commented Nov 13, 2023

@jviau jviau closed this as completed Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 Reliability Durable functions get stuck or don’t run as expected.
Projects
None yet
Development

No branches or pull requests

3 participants