Commit bf9ab0f3 authored by Timothy Andrew's avatar Timothy Andrew

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.
parent bf28506f
...@@ -6,13 +6,11 @@ class DestroyGroupService ...@@ -6,13 +6,11 @@ class DestroyGroupService
end end
def async_execute def async_execute
group.transaction do
# Soft delete via paranoia gem # Soft delete via paranoia gem
group.destroy group.destroy
job_id = GroupDestroyWorker.perform_async(group.id, current_user.id) 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}") Rails.logger.info("User #{current_user.id} scheduled a deletion of group ID #{group.id} with job ID #{job_id}")
end end
end
def execute def execute
group.projects.each do |project| group.projects.each do |project|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment