-
Notifications
You must be signed in to change notification settings - Fork 696
Refactor ParameterResource to use Lazy initialization for value retrieval #10361
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
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.
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.
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
_hasValue
flag and_value
field in favor of the built-in lazy initialization pattern - Simplifies the
ValueInternal
property implementation
ArgumentNullException.ThrowIfNull(callback); | ||
|
||
_valueGetter = callback; | ||
_lazyValue = new Lazy<string>(() => _valueGetter(Default)); |
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.
What is the default safety mode when not specified explicitly? Is it thread safe?
I think it would be clearer to specify it explicitly.
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.
ExecutionAndPublication, the one that you always want by default 😄
* 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>
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.