From ab0e82d656921bb22a8ec7667ac721084061c0a2 Mon Sep 17 00:00:00 2001 From: Kyriakos Z <3829551+koox00@users.noreply.github.com> Date: Thu, 19 Aug 2021 22:20:26 +0300 Subject: [PATCH] Fixes race condition in notification.go (#18226) * Fixes race condition in notification.go Appending is not thread safe, this commit makes followers a map so we can add new followers from autofollow, and then adds those again to followers. * Fixes race condition --- app/notification.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/notification.go b/app/notification.go index 9c8188555c..2bbb206e41 100644 --- a/app/notification.go +++ b/app/notification.go @@ -255,12 +255,12 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod return } + followersMutex.Lock() // add new followers to existing followers if threadMembership.Following && !followers.Contains(userID) { - followersMutex.Lock() followers = append(followers, userID) - followersMutex.Unlock() } + followersMutex.Unlock() membershipsMutex.Lock() participantMemberships[userID] = threadMembership