]> cat aescling's git repositories - mastodon.git/commitdiff
Prevent multiple handlers for Delete of Actor from running (#9292)
authorEugen Rochko <eugen@zeonfederated.com>
Fri, 16 Nov 2018 18:46:23 +0000 (19:46 +0100)
committerGitHub <noreply@github.com>
Fri, 16 Nov 2018 18:46:23 +0000 (19:46 +0100)
app/lib/activitypub/activity.rb
app/lib/activitypub/activity/delete.rb

index 999954cb5bc9944e3b8eff348abf57e3906aa9b1..0a729011f225603e953f694bdc84eb793debc16c 100644 (file)
@@ -129,4 +129,10 @@ class ActivityPub::Activity
       ::FetchRemoteStatusService.new.call(@object['url'])
     end
   end
+
+  def lock_or_return(key, expire_after = 7.days.seconds)
+    yield if redis.set(key, true, nx: true, ex: expire_after)
+  ensure
+    redis.del(key)
+  end
 end
index 457047ac060fb26006c8cb9a8d6b20d51f7761a4..8270fed1b20a6bbaa023aba9cc7c548a5431f5fa 100644 (file)
@@ -12,8 +12,10 @@ class ActivityPub::Activity::Delete < ActivityPub::Activity
   private
 
   def delete_person
-    SuspendAccountService.new.call(@account)
-    @account.destroy!
+    lock_or_return("delete_in_progress:#{@account.id}") do
+      SuspendAccountService.new.call(@account)
+      @account.destroy!
+    end
   end
 
   def delete_note