Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Text;
using DurableTask.Core;
using DurableTask.Core.Command;
using DurableTask.Core.Entities;
Expand Down Expand Up @@ -73,6 +74,8 @@ internal bool TryGetOrchestrationErrorDetails(out Exception? failure)

internal void SetResult(IEnumerable<OrchestratorAction> actions, string customStatus)
{
ValidateCustomStatusSize(customStatus);

var result = new OrchestratorExecutionResult
{
CustomStatus = customStatus,
Expand Down Expand Up @@ -182,5 +185,20 @@ private void SetResultInternal(OrchestratorExecutionResult result)

this.executionResult = result;
}

private static void ValidateCustomStatusSize(string customStatus)
{
// Azure Table Storage enforces a 32 KB limit if a property value is a UTF-16 encoded string.
// We apply a 16 KB limit here to align with our in-process model.
const int MaxCustomStatusSizeInKB = 16;
double customStatusSizeInKB = customStatus != null ? Encoding.Unicode.GetByteCount(customStatus) / 1024.0 : 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but do we really need floating-point computation here? Consider defining the constant as 16*1024 and just comparing it with the GetByteCount result. This may be more performant (though the impact is probably negligible) but, more importantly, this will eliminate some mental overhead for the reader of this code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, Anatoli! This was changed like this because of this comment .


// If the provided custom status value exceeds 16KB in size, fail the orchestration.
if (customStatusSizeInKB > MaxCustomStatusSizeInKB)
{
throw new ArgumentException(
$"CustomStatus is too large: limit = {MaxCustomStatusSizeInKB} KB (UTF-16), actual = {customStatusSizeInKB:N2} KB.");
}
}
}
}
Loading