-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Fix Options Source Gen RangeAttribute Thread Safety #97045
Fix Options Source Gen RangeAttribute Thread Safety #97045
Conversation
Tagging subscribers to this area: @dotnet/area-extensions-options Issue DetailsThe source generator for the RangeAttribute creates code optimizing the generation of multiple instances of the RangeAttribute with identical parameters when used in various locations. However, the initialization code within the generated RangeAttribute was not thread safe. This presents an issue when the initialization code is executed concurrently from multiple threads. The solution is straightforward: implement thread safety measures in the initialization code.
|
3a02e31
to
c8d2f31
Compare
reviewers, please hide the white space diffs when reviewing the change for simplicity. |
...raries/Microsoft.Extensions.Options/tests/SourceGeneration.Unit.Tests/OptionsRuntimeTests.cs
Outdated
Show resolved
Hide resolved
...raries/Microsoft.Extensions.Options/tests/SourceGeneration.Unit.Tests/OptionsRuntimeTests.cs
Outdated
Show resolved
Hide resolved
...raries/Microsoft.Extensions.Options/tests/SourceGeneration.Unit.Tests/OptionsRuntimeTests.cs
Outdated
Show resolved
Hide resolved
@@ -338,47 +338,53 @@ public __SourceGen__RangeAttribute(global::System.Type type, string minimum, str | |||
public bool ConvertValueInInvariantCulture { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For these properties that have a public setter, who is calling set on them, and when? They're used as part of IsValid, so I'm wondering if it's possible they might be changed concurrently with its execution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is helper property usually called only when declaring the RangeAttribute. Something like [RangeAttribute(typeof(TimeSpan), "01:00:00", "23:59:59", ConvertValueInInvariantCulture = true)]
.
...ies/Microsoft.Extensions.Options/tests/SourceGenerationTests/Baselines/NetFX/Validators.g.cs
Outdated
Show resolved
Hide resolved
/backport to release/8.0 |
Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/7560572213 |
@tarekgh backporting to release/8.0 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Fix Options Source Gen RangeAttribute Thread Safety
Using index info to reconstruct a base tree...
M src/libraries/Microsoft.Extensions.Options/gen/Emitter.cs
A src/libraries/Microsoft.Extensions.Options/tests/SourceGeneration.Unit.Tests/Baselines/OptionsExtendingSystemClassTest.netcore.g.cs
A src/libraries/Microsoft.Extensions.Options/tests/SourceGeneration.Unit.Tests/Baselines/OptionsExtendingSystemClassTest.netfx.g.cs
M src/libraries/Microsoft.Extensions.Options/tests/SourceGenerationTests/Baselines/NetCoreApp/Validators.g.cs
M src/libraries/Microsoft.Extensions.Options/tests/SourceGenerationTests/Baselines/NetFX/Validators.g.cs
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/Microsoft.Extensions.Options/tests/SourceGenerationTests/Baselines/NetFX/Validators.g.cs
Auto-merging src/libraries/Microsoft.Extensions.Options/tests/SourceGenerationTests/Baselines/NetCoreApp/Validators.g.cs
CONFLICT (modify/delete): src/libraries/Microsoft.Extensions.Options/tests/SourceGeneration.Unit.Tests/Baselines/OptionsExtendingSystemClassTest.netfx.g.cs deleted in HEAD and modified in Fix Options Source Gen RangeAttribute Thread Safety. Version Fix Options Source Gen RangeAttribute Thread Safety of src/libraries/Microsoft.Extensions.Options/tests/SourceGeneration.Unit.Tests/Baselines/OptionsExtendingSystemClassTest.netfx.g.cs left in tree.
CONFLICT (modify/delete): src/libraries/Microsoft.Extensions.Options/tests/SourceGeneration.Unit.Tests/Baselines/OptionsExtendingSystemClassTest.netcore.g.cs deleted in HEAD and modified in Fix Options Source Gen RangeAttribute Thread Safety. Version Fix Options Source Gen RangeAttribute Thread Safety of src/libraries/Microsoft.Extensions.Options/tests/SourceGeneration.Unit.Tests/Baselines/OptionsExtendingSystemClassTest.netcore.g.cs left in tree.
Auto-merging src/libraries/Microsoft.Extensions.Options/gen/Emitter.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Fix Options Source Gen RangeAttribute Thread Safety
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
@tarekgh an error occurred while backporting to release/8.0, please check the run log for details! Error: git am failed, most likely due to a merge conflict. |
I opened the issue #97112 for tracking the unrelated failure |
* Fix Options Source Gen RangeAttribute Thread Safety * Address the feedback * More feedback addressing * Feedback++
#97037
The source generator for the RangeAttribute creates code optimizing the generation of multiple instances of the RangeAttribute with identical parameters when used in various locations. However, the initialization code within the generated RangeAttribute was not thread safe. This presents an issue when the initialization code is executed concurrently from multiple threads. The solution is straightforward: implement thread safety measures in the initialization code.