-
Notifications
You must be signed in to change notification settings - Fork 5k
Lock EnsureConfigured to prevent initialization issues in JsonTypeInfo #68605
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,19 +195,27 @@ internal JsonTypeInfo(Type type, JsonConverter converter, JsonSerializerOptions | |
} | ||
|
||
private bool _isConfigured; | ||
private object _configureLock = new object(); | ||
|
||
internal void EnsureConfigured() | ||
{ | ||
if (_isConfigured) | ||
return; | ||
|
||
Configure(); | ||
lock (_configureLock) | ||
{ | ||
if (_isConfigured) | ||
return; | ||
|
||
Configure(); | ||
|
||
_isConfigured = true; | ||
_isConfigured = true; | ||
} | ||
} | ||
|
||
internal virtual void Configure() | ||
{ | ||
Debug.Assert(Monitor.IsEntered(_configureLock), "Configure called directly, use EnsureConfigured which locks this method"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is virtual, might make sense to add the same to any overrides? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they will call base.Configure anyway There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. That might change in future iterations, but I guess nothing prevents users from overriding the Configure method elsewhere either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the method be changed to |
||
JsonConverter converter = PropertyInfoForTypeInfo.ConverterBase; | ||
Debug.Assert(PropertyInfoForTypeInfo.ConverterStrategy == PropertyInfoForTypeInfo.ConverterBase.ConverterStrategy, | ||
$"ConverterStrategy from PropertyInfoForTypeInfo.ConverterStrategy ({PropertyInfoForTypeInfo.ConverterStrategy}) does not match converter's ({PropertyInfoForTypeInfo.ConverterBase.ConverterStrategy})"); | ||
|
Uh oh!
There was an error while loading. Please reload this page.