Skip to content

the key caching has some race conditions - #360

Draft
daryl-mcmillan wants to merge 2 commits into
mainfrom
key-dispose-race-conditions
Draft

the key caching has some race conditions#360
daryl-mcmillan wants to merge 2 commits into
mainfrom
key-dispose-race-conditions

Conversation

@daryl-mcmillan

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

Copy link
Copy Markdown

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();

@daryl-mcmillan daryl-mcmillan Feb 8, 2024

Copy link
Copy Markdown
Author

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 GetCurrentToken() {
lock( m_keyRefreshLock ) {
return m_current?.Ref();

Copy link
Copy Markdown
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