From 935405f19d4a0d78f1a84964460635ec5a091e0c Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Mon, 1 May 2017 17:40:04 -0400 Subject: Copy users in/out out profileByIds cache to prevent data race (#6179) --- store/sql_user_store.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'store') diff --git a/store/sql_user_store.go b/store/sql_user_store.go index 9d981b13e..d18da8df8 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -814,7 +814,8 @@ func (us SqlUserStore) GetProfileByIds(userIds []string, allowFromCache bool) St if allowFromCache { for _, userId := range userIds { if cacheItem, ok := profileByIdsCache.Get(userId); ok { - u := cacheItem.(*model.User) + u := &model.User{} + *u = *cacheItem.(*model.User) users = append(users, u) } else { remainingUserIds = append(remainingUserIds, userId) @@ -855,7 +856,9 @@ func (us SqlUserStore) GetProfileByIds(userIds []string, allowFromCache bool) St for _, u := range users { u.Sanitize(map[string]bool{}) - profileByIdsCache.AddWithExpiresInSecs(u.Id, u, PROFILE_BY_IDS_CACHE_SEC) + cpy := &model.User{} + *cpy = *u + profileByIdsCache.AddWithExpiresInSecs(cpy.Id, cpy, PROFILE_BY_IDS_CACHE_SEC) } result.Data = users -- cgit v1.2.3-1-g7c22