Skip to content

Fix infinite recursion validating commands with cyclic object graphs#2309

Merged
woksin merged 1 commit into
mainfrom
fix/fluent-validation-cyclic-graph-recursion
Jun 20, 2026
Merged

Fix infinite recursion validating commands with cyclic object graphs#2309
woksin merged 1 commit into
mainfrom
fix/fluent-validation-cyclic-graph-recursion

Conversation

@woksin

@woksin woksin commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Fixed

  • Commands with a property holding a cyclic or arbitrary object graph (for example System.Text.Json.Nodes.JsonObject, whose child nodes back-reference their parent) no longer crash command execution with a stack overflow / HTTP 500. Nested validator behavior is unchanged.

The command FluentValidationFilter walks every public property of every
complex command property to run nested validators. Object graphs with
back-references — notably System.Text.Json.Nodes.JsonObject, whose child
nodes point back to their parent — caused the walk to recurse forever and
overflow the stack (HTTP 500).

Track visited reference-type instances with a ReferenceEqualityComparer-keyed
set so any cycle terminates. Identity keying preserves existing behavior:
distinct-but-equal values (e.g. two equal concept values in a list) are each
still validated, and unvalidated nested types are still walked to reach
deeper validators.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@woksin woksin added the patch label Jun 20, 2026
@github-actions

Copy link
Copy Markdown

NuGet packages for this PR, e.g. Cratis.Arc:
https://github.com/cratis/arc/packages/1655206?version=20.45.0

@woksin woksin merged commit 1d81840 into main Jun 20, 2026
50 checks passed
@woksin woksin deleted the fix/fluent-validation-cyclic-graph-recursion branch June 20, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant