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

the key caching has some race conditions #360

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

daryl-mcmillan
Copy link

@daryl-mcmillan daryl-mcmillan commented Feb 8, 2024

This is assuming the reference counting via Dispose() is reasonable - really multiple Dispose calls are supposed to be ok so Ref() should probably be returning a wrapper.
https://stackoverflow.com/a/5306896/24158

return null;
}

return current.Ref();
Copy link
Author

@daryl-mcmillan daryl-mcmillan Feb 8, 2024

Choose a reason for hiding this comment

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

this is the main race condition - if the key is replaced between Volatile.Read and this call to .Ref() it will be disposed.

private D2LSecurityToken m_current = null;

private D2LSecurityToken GetCurrentToken() {
lock( m_keyRefreshLock ) {
return m_current?.Ref();
Copy link
Author

Choose a reason for hiding this comment

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

don't let the key be disposed while we're thinking about returning it.

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.

1 participant