[3.0.1 backport] Fix race condition caused when getting user roles
Description
A race condition has been discovered in GetRoles() caused by the nil check, and the user.roles write being done at the same time when replicating 2 documents (with channels) with a custom sync function, and using users with explicit channels.
This needs to be fixed to make sure this function does not race. This can be done by adding a lock on the userImp struct and then using a read lock, and upgrading it when needed.
A race condition has been discovered in
GetRoles()
caused by the nil check, and theuser.roles
write being done at the same time when replicating 2 documents (with channels) with a custom sync function, and using users with explicit channels.This needs to be fixed to make sure this function does not race. This can be done by adding a lock on the
userImp
struct and then using a read lock, and upgrading it when needed.