Use per-command option instances in AspNetCore.CommandLine - #9893
#9893Merged
glen-84 merged 1 commit intoJun 11, 2026
mainChilliCream/graphql-platform:mainfrom
gai/per-instance-command-line-optionsChilliCream/graphql-platform:gai/per-instance-command-line-optionsCopy head branch name to clipboard
Merged
Use per-command option instances in AspNetCore.CommandLine#9893glen-84 merged 1 commit intomainChilliCream/graphql-platform:mainfrom gai/per-instance-command-line-optionsChilliCream/graphql-platform:gai/per-instance-command-line-optionsCopy head branch name to clipboard
glen-84 merged 1 commit into
mainChilliCream/graphql-platform:mainfrom
gai/per-instance-command-line-optionsChilliCream/graphql-platform:gai/per-instance-command-line-optionsCopy head branch name to clipboard
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes shared System.CommandLine symbol singletons from AspNetCore.CommandLine to avoid racy, cross-command-tree option reuse when multiple CLI App instances are constructed concurrently (per System.CommandLine maintainers’ non-thread-safe guidance).
Changes:
- Deleted the
Opt<TOption>static singleton helper that sharedOptioninstances across command trees. - Updated
PrintCommandandExportCommandto create per-commandOptioninstances and capture them in the action closure used forparseResult.GetValue(...).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/HotChocolate/AspNetCore/src/AspNetCore.CommandLine/Helpers/Opt.cs | Removes the singleton option factory that could introduce cross-tree races. |
| src/HotChocolate/AspNetCore/src/AspNetCore.CommandLine/Command/PrintCommand.cs | Uses a per-command SchemaNameOption instance and retrieves values via the captured instance. |
| src/HotChocolate/AspNetCore/src/AspNetCore.CommandLine/Command/ExportCommand.cs | Uses per-command OutputOption / SchemaNameOption / SemanticNonNullOption instances and retrieves values via captured instances. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Jun 16, 2026
This was referenced Jun 24, 2026
This was referenced Jul 2, 2026
Open
This was referenced Jul 13, 2026
This was referenced Jul 20, 2026
chore(deps): Bump HotChocolate.Subscriptions.InMemory from 15.1.14 to 16.5.1
Kuestenlogik/Bowire#506
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
System.CommandLine symbols (
Command,Option,Argument) are intentionally not thread-safe per the maintainers (dotnet/command-line-api#1258). TheOpt<TOption>static singleton helper inAspNetCore.CommandLineshared option instances across allAppcommand trees, and its lazy??=initialization is racy. When multipleAppinstances are constructed concurrently (as the parallel test classes inAspNetCore.CommandLine.Testsdo), a command tree could end up holding a different option instance than the one its action later passes toparseResult.GetValue, which silently returnsnull. Forschema exportthis meant the--outputvalue was dropped and the schema was exported to the current directory with exit code 0, surfacing as an intermittent snapshot failure inSchemaExportCommandTestson CI.Each command now creates its own option instances and captures them in its action closure, removing all shared symbol state between command trees. The
Opt<T>helper is deleted.The Nitro CLI has its own copy of the same pattern; that is left for a follow-up.
Test plan
dotnet testonAspNetCore.CommandLine.Tests(net10.0): all 12 tests pass.--outputin 36/5000 simulated process starts with the singleton pattern); the per-instance design removes the shared state that race requires.