Skip to content

Commit

Permalink
fix: make JsonDiffer thread safe (#683)
Browse files Browse the repository at this point in the history
Concurrent execution of JsonDiffer() on multiple threads causes
ArgumentOutOfRangeException during Dispose().
Create new instance of JsonPatchDeltaFormatter for every call.
Please refer to this issue:
#682

---------

Co-authored-by: AVEVA\rajani.rao <[email protected]>
Co-authored-by: Christoph Bühler <[email protected]>
  • Loading branch information
3 people committed Jan 17, 2024
1 parent ea8444e commit 9389f8a
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace KubeOps.Operator.Web.Webhooks.Admission.Mutation;

internal static class JsonDiffer
{
private static readonly JsonPatchDeltaFormatter Formatter = new();

public static string Base64Diff(this JsonNode from, object? to)
{
var formatter = new JsonPatchDeltaFormatter();

var toToken = GetNode(to);
var patch = from.Diff(toToken, Formatter)!;
var patch = from.Diff(toToken, formatter)!;

return Convert.ToBase64String(Encoding.UTF8.GetBytes(patch.ToString()));
}
Expand Down

0 comments on commit 9389f8a

Please sign in to comment.