Refactor ParameterResource to use Lazy initialization for value retrieval#10361
Merged
Refactor ParameterResource to use Lazy initialization for value retrieval#10361
Conversation
…eval - This is to prevent generated parameters from being accessed concurrently and generating different values. This is more of a concern now because of asynchrony.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the ParameterResource class to use lazy initialization for parameter value retrieval to prevent race conditions when generated parameters are accessed concurrently. The change addresses a flaky test issue that became more prevalent after introducing asynchrony in parameter resolution.
- Replaces manual caching logic with
Lazy<string>for thread-safe value initialization - Removes the custom
_hasValueflag and_valuefield in favor of the built-in lazy initialization pattern - Simplifies the
ValueInternalproperty implementation
JamesNK
reviewed
Jul 14, 2025
| ArgumentNullException.ThrowIfNull(callback); | ||
|
|
||
| _valueGetter = callback; | ||
| _lazyValue = new Lazy<string>(() => _valueGetter(Default)); |
Member
There was a problem hiding this comment.
What is the default safety mode when not specified explicitly? Is it thread safe?
I think it would be clearer to specify it explicitly.
Contributor
Author
There was a problem hiding this comment.
ExecutionAndPublication, the one that you always want by default 😄
JamesNK
approved these changes
Jul 14, 2025
davidfowl
added a commit
that referenced
this pull request
Jul 14, 2025
davidfowl
added a commit
that referenced
this pull request
Jul 15, 2025
* Force async execution of resource startup - Previously we didn't preemptively dispatch to the threadpool per resource on startup. That causes issues blocking other resource's startup because of a single blocking call. This change dispatching preemptively before creating the dcp resource. * Refactor ParameterResource to use Lazy initialization for value retrieval (#10361) --------- Co-authored-by: David Fowler <davidfowl@gmail.com>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Found in a new flaky test after the async parameter PR:
Throwing agent mode at test logs is 👨🏾🍳
PS: This was a problem before but is more prevalent now because we introduced asynchrony in parameter resolution.