From d26c4509ea850cdf391115f01e5b9eb6bf534553 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 27 May 2019 15:41:57 -0400 Subject: [PATCH] FIX: Adding a user to a group twice under concurrency This prevents an error from being raised / logged. --- app/controllers/groups_controller.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 7a632eb8f6a..a9530d1aac0 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -321,8 +321,14 @@ class GroupsController < ApplicationController )) else users.each do |user| - group.add(user) - GroupActionLogger.new(current_user, group).log_add_user_to_group(user) + begin + group.add(user) + GroupActionLogger.new(current_user, group).log_add_user_to_group(user) + rescue ActiveRecord::RecordNotUnique + # Under concurrency, we might attempt to insert two records quickly and hit a DB + # constraint. In this case we can safely ignore the error and act as if the user + # was added to the group. + end end render json: success_json.merge!(