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

[bug]: Mutation WebHook throws JsonDiff ArgumentOutOfRangeException exception #682

Closed
rajaniraog opened this issue Dec 18, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@rajaniraog
Copy link
Contributor

Describe the bug

When mutiple Mutation WebHooks are created simultaneously with changes, resulting in modified MutationResult(), the

  1. AdmissionResponse IAdmissionWebhook<TEntity, MutationResult>.TransformResult(MutationResult result, AdmissionRequest<TEntity> request) invokes KubernetesJsonDiffer.DiffObjects(from, to); gets invoked which then calls KubernetesJsonDiffer.DiffObjects(from, to); which isn't thread safe due to using a `static JsonPatchDeltaFormatter Formatter = new();``

To reproduce

Make simultaneous calls to Mutation WebHooks MutationResult IAdmissionWebhook<TEntity, MutationResult>.Create(TEntity newEntity, bool dryRun) results in System.ArgumentOutOfRangeException. See additional context below for full callstack.

Expected behavior

No exception should occur when making simultaneous calls to Mutation WebHooks with a modified MutationResult()

Screenshots

No response

Additional Context

An error happened during admission.
      System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than or equal to the size of the collection. (Parameter 'length')
         at System.Text.StringBuilder.Remove(Int32 startIndex, Int32 length)
         at System.Text.Json.JsonDiffPatch.Diffs.Formatters.JsonPatchDeltaFormatter.PropertyPathScope.Dispose()
         at System.Text.Json.JsonDiffPatch.Diffs.Formatters.JsonPatchDeltaFormatter.FormatObjectProperty(JsonDiffDelta& delta, JsonNode left, String propertyName, JsonNode existingValue)
         at System.Text.Json.JsonDiffPatch.Diffs.Formatters.DefaultDeltaFormatter`1.FormatObject(JsonDiffDelta& delta, JsonObject left, TResult existingValue)
         at System.Text.Json.JsonDiffPatch.Diffs.Formatters.DefaultDeltaFormatter`1.FormatJsonDiffDelta(JsonDiffDelta& delta, JsonNode left, TResult existingValue)
         at System.Text.Json.JsonDiffPatch.Diffs.Formatters.DefaultDeltaFormatter`1.Format(JsonDiffDelta& delta, JsonNode left)
         at System.Text.Json.JsonDiffPatch.JsonDiffPatcher.DiffAndFormat[TResult](JsonNode left, JsonNode right, IJsonDiffDeltaFormatter`1 formatter, JsonDiffOptions options)
         at System.Text.Json.JsonDiffPatch.JsonDiffPatcher.Diff[TResult](JsonNode left, JsonNode right, IJsonDiffDeltaFormatter`1 formatter, JsonDiffOptions options)
         at KubeOps.Operator.Webhooks.KubernetesJsonDiffer.DiffObjects(Object from, Object to) in ..\dotnet-operator-sdk-release\src\KubeOps\Operator\Webhooks\KubernetesJsonDiffer.cs:line 18
         at KubeOps.Operator.Webhooks.IMutationWebhook`1.KubeOps.Operator.Webhooks.IAdmissionWebhook<TEntity,KubeOps.Operator.Webhooks.MutationResult>.TransformResult(MutationResult result, AdmissionRequest`1 request, ILogger logger) in ..\dotnet-operator-sdk-release\src\KubeOps\Operator\Webhooks\IMutationWebhook{TEntity}.cs:line 87
         at KubeOps.Operator.Webhooks.IAdmissionWebhook`2.<Register>b__15_0(HttpContext context)
@rajaniraog rajaniraog added the bug Something isn't working label Dec 18, 2023
@rajaniraog
Copy link
Contributor Author

rajaniraog commented Dec 18, 2023

PR created with fix: #683
Would it be possible to put this patch for v7.6.1 .Net 7.0 release please?

buehler added a commit that referenced this issue Dec 27, 2023
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>
@buehler
Copy link
Owner

buehler commented Dec 27, 2023

Hey @rajaniraog

I can try :)
It will not be easy since the main branch has diverged pretty heavy compared to the release branch. I hoped to release v8 before new year.

@buehler buehler closed this as completed Dec 27, 2023
buehler added a commit that referenced this issue Jan 17, 2024
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>
buehler added a commit that referenced this issue Jan 17, 2024
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants