Merge pull request #24176 from vitlibar/fix-race-condition-in-context-access

Fix race condition in ContextAccess
This commit is contained in:
Maksim Kita 2021-05-17 23:01:01 +03:00 committed by GitHub
commit 5e7ca811fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -143,11 +143,13 @@ ContextAccess::ContextAccess(const AccessControlManager & manager_, const Params
: manager(&manager_)
, params(params_)
{
std::lock_guard lock{mutex};
subscription_for_user_change = manager->subscribeForChanges(
*params.user_id, [this](const UUID &, const AccessEntityPtr & entity)
{
UserPtr changed_user = entity ? typeid_cast<UserPtr>(entity) : nullptr;
std::lock_guard lock{mutex};
std::lock_guard lock2{mutex};
setUser(changed_user);
});
@ -189,7 +191,7 @@ void ContextAccess::setUser(const UserPtr & user_) const
current_roles_with_admin_option = user->granted_roles.findGrantedWithAdminOption(params.current_roles);
}
subscription_for_roles_changes = {};
subscription_for_roles_changes.reset();
enabled_roles = manager->getEnabledRoles(current_roles, current_roles_with_admin_option);
subscription_for_roles_changes = enabled_roles->subscribeForChanges([this](const std::shared_ptr<const EnabledRolesInfo> & roles_info_)
{