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 <rajani.rao@aveva.com>
Co-authored-by: Christoph Bühler <buehler@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 17, 2024
1 parent 00d70a7 commit 5379ee3
Showing 1 changed file with 3 additions and 3 deletions.
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 5379ee3

Please sign in to comment.