From bf9ab0f33d65df1566fcde8100576d23f5c77a4f Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Thu, 17 Nov 2016 17:23:41 +0530 Subject: Fix a race condition that allowed soft-deleted groups to remain in the database. The intended flow is: Soft-delete group (sync) -> Delete group projects (async) -> Hard-delete group (async) The soft-delete was run in a transaction, which was committed only after the async job (for hard-deletion) was kicked off. There was a race condition here - the soft-delete transaction could complete _after_ the hard delete completed, leaving a soft-deleted record in the database. This commit removes this race condition. There is no need to run the soft-delete in a transaction. The soft-delete completes before the async job is kicked off. --- app/services/destroy_group_service.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/services/destroy_group_service.rb b/app/services/destroy_group_service.rb index 0081364b8aa..a880952e274 100644 --- a/app/services/destroy_group_service.rb +++ b/app/services/destroy_group_service.rb @@ -6,12 +6,10 @@ class DestroyGroupService end def async_execute - group.transaction do - # Soft delete via paranoia gem - group.destroy - job_id = GroupDestroyWorker.perform_async(group.id, current_user.id) - Rails.logger.info("User #{current_user.id} scheduled a deletion of group ID #{group.id} with job ID #{job_id}") - end + # Soft delete via paranoia gem + group.destroy + job_id = GroupDestroyWorker.perform_async(group.id, current_user.id) + Rails.logger.info("User #{current_user.id} scheduled a deletion of group ID #{group.id} with job ID #{job_id}") end def execute -- cgit v1.2.1