Skip to content

Fix #158 #159

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

Merged
merged 1 commit into from
Apr 28, 2021
Merged

Fix #158 #159

merged 1 commit into from
Apr 28, 2021

Conversation

wravery
Copy link
Contributor

@wravery wravery commented Apr 28, 2021

There's a race condition in Schema::WrapType where it caches the WrapperType in a map, keyed off of the original type. If you perform query validation on multiple threads, they may simultaneously lookup and emplace new values in the cache, invalidating the iterators on one of them, possibly resulting in duplicate entries.

I'm using a std::shared_mutex as a reader/writer lock on each of these maps. It can find a match with a std::shared_lock, and if there is no match, it'll trade that for a std::unique_lock and perform the emplace, which is equivalent to a find if the key was added on another thread before acquiring the std::unique_lock.

@wravery wravery merged commit 0929f3e into microsoft:main Apr 28, 2021
@wravery wravery deleted the wraptype-shared-mutex branch April 28, 2021 23:12
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