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

Remove several Lazy-related objects from every TokenValidationResult #2180

Merged
merged 2 commits into from
Jul 28, 2023

Conversation

stephentoub
Copy link
Collaborator

Creating a TokenValidationResult is also creating a Lazy<>, a LazyHelper internal to the Lazy<>, and a Func<> delegate due to the lambda passed to the lazy closing over this.

It's not clear to me why Lazy<> was being used here. There's other lazily-initialized state on the same type that's not using Lazy<>, and I went back and looked at the PR/issue that added this and there's no discussion of it. Is there some kind of thread-safety guarantee it was trying to provide? Or was this just done this way because that's how the dev happened to write it?

@jennyf19 jennyf19 added this to the 7.0.0-preview2 milestone Jul 27, 2023
@stephentoub
Copy link
Collaborator Author

@brentschmaltz, based on our offline conversation, I revamped it. Please take a look and let me know if this matches your expectations for what's synchronized and how.

Creating a TokenValidationResult is also creating a `Lazy<>`, a `LazyHelper` internal to the `Lazy<>`, and a `Func<>` delegate due to the lambda passed to the lazy closing over `this`. Offline discussion also suggested that thread-safe initialization is important, including for ClaimsIdentity which isn't currently protected. So instead, this commit changes the scheme employed to use double-checked locking directly for ClaimsIdentity and then optimistic synchronization with Interlocked for Claims, as well as for the separate property bag property that was previously always instantiated.
@brentschmaltz brentschmaltz added this pull request to the merge queue Jul 28, 2023
Merged via the queue into AzureAD:dev7x with commit 96eec29 Jul 28, 2023
brentschmaltz pushed a commit that referenced this pull request Jul 28, 2023
…2180)

* Remove several Lazy-related objects from every TokenValidationResult

Creating a TokenValidationResult is also creating a `Lazy<>`, a `LazyHelper` internal to the `Lazy<>`, and a `Func<>` delegate due to the lambda passed to the lazy closing over `this`. Offline discussion also suggested that thread-safe initialization is important, including for ClaimsIdentity which isn't currently protected. So instead, this commit changes the scheme employed to use double-checked locking directly for ClaimsIdentity and then optimistic synchronization with Interlocked for Claims, as well as for the separate property bag property that was previously always instantiated.

* Address PR feedback
brentschmaltz pushed a commit that referenced this pull request Jul 28, 2023
…2180)

* Remove several Lazy-related objects from every TokenValidationResult

Creating a TokenValidationResult is also creating a `Lazy<>`, a `LazyHelper` internal to the `Lazy<>`, and a `Func<>` delegate due to the lambda passed to the lazy closing over `this`. Offline discussion also suggested that thread-safe initialization is important, including for ClaimsIdentity which isn't currently protected. So instead, this commit changes the scheme employed to use double-checked locking directly for ClaimsIdentity and then optimistic synchronization with Interlocked for Claims, as well as for the separate property bag property that was previously always instantiated.

* Address PR feedback
brentschmaltz pushed a commit that referenced this pull request Sep 6, 2023
…2180)

* Remove several Lazy-related objects from every TokenValidationResult

Creating a TokenValidationResult is also creating a `Lazy<>`, a `LazyHelper` internal to the `Lazy<>`, and a `Func<>` delegate due to the lambda passed to the lazy closing over `this`. Offline discussion also suggested that thread-safe initialization is important, including for ClaimsIdentity which isn't currently protected. So instead, this commit changes the scheme employed to use double-checked locking directly for ClaimsIdentity and then optimistic synchronization with Interlocked for Claims, as well as for the separate property bag property that was previously always instantiated.

* Address PR feedback
brentschmaltz pushed a commit that referenced this pull request Sep 7, 2023
…2180)

* Remove several Lazy-related objects from every TokenValidationResult

Creating a TokenValidationResult is also creating a `Lazy<>`, a `LazyHelper` internal to the `Lazy<>`, and a `Func<>` delegate due to the lambda passed to the lazy closing over `this`. Offline discussion also suggested that thread-safe initialization is important, including for ClaimsIdentity which isn't currently protected. So instead, this commit changes the scheme employed to use double-checked locking directly for ClaimsIdentity and then optimistic synchronization with Interlocked for Claims, as well as for the separate property bag property that was previously always instantiated.

* Address PR feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants