Skip to content
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

Lock EnsureConfigured to prevent initialization issues in JsonTypeInfo #68605

Merged
merged 2 commits into from
Apr 28, 2022

Conversation

krwq
Copy link
Member

@krwq krwq commented Apr 27, 2022

Fixes: #67816
Fixes: #68584
Contributes to: #67761

Replaces: #68480

It's theoretically possible to achieve this without having to use locks (which I've tried in the replaced PR) but:

  • this is affecting many PRs
  • most likely there are more initialization issues than just the one I addressed in the replaced PR
  • lock-less behavior will make this code very prone to re-introducing initialization issues
  • this lock will only happen once per initialization of JsonTypeInfo which is supposedly happening only once per type per options so it's single time cost (minus multiple threads trying to do the same initialization)

@ghost
Copy link

ghost commented Apr 27, 2022

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes: #67816
Fixes: #68584
Contributes to: #67761

Replaces: #68480

It's theoretically possible to achieve this without having to use locks (which I've tried in the replaced PR) but:

  • this is affecting many PRs
  • most likely there are more initialization issues than just the one I addressed in the replaced PR
  • lock-less behavior will make this code very prone to re-introducing initialization issues
  • this lock will only happen once per initialization of JsonTypeInfo which is supposedly happening only once per type per options so it's single time cost (minus multiple threads trying to do the same initialization)
Author: krwq
Assignees: -
Labels:

area-System.Text.Json

Milestone: -

Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also remove the various debug formatting methods?

@krwq
Copy link
Member Author

krwq commented Apr 27, 2022

@eiriktsarpalis if any of those debug ever fails the information will be very useful - I personally prefer to keep them but can remove if you feel strongly about it

}

internal virtual void Configure()
{
Debug.Assert(Monitor.IsEntered(_configureLock), "Configure called directly, use EnsureConfigured which locks this method");
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they will call base.Configure anyway

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the method be changed to protected virtual instead?

@eiriktsarpalis
Copy link
Member

@eiriktsarpalis Eirik Tsarpalis FTE if any of those debug ever fails the information will be very useful - I personally prefer to keep them but can remove if you feel strongly about it

I feel that they were specifically crafted for debugging the issue at hand. If other issues come by in the future the information might not be relevant. I think we should just remove them.

@krwq
Copy link
Member Author

krwq commented Apr 28, 2022

They were made to debug any JsonTypeInfo/JsonPropertyInfo issues. There are still couple of other flaky issues other than the one mentioned - I'm not yet sure if that will be useful for debugging those or not. Also this is super useful when making changes and something goes wrong or gets regressed (I had to explore these information many times under debugger when doing prototyping for contract resolver and that actually makes it much easier to extract). I'll leave this for now and we can clean it up once we are confident our tests are not blocking CI runs

@krwq
Copy link
Member Author

krwq commented Apr 28, 2022

There seem to be some infra issue, I couldn't see any timeout in any of the JSON helix items

@krwq krwq merged commit 7654bf2 into dotnet:main Apr 28, 2022
@ghost ghost locked as resolved and limited conversation to collaborators May 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants