diff options
author | ThibG <thib@sitedethib.com> | 2019-03-16 20:18:47 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2019-03-16 20:18:47 +0100 |
commit | 6b0eda14a11ba243e7adf3900aae75ba23980c96 (patch) | |
tree | aaef24a6703dcc797f0d63402a8d94ab922c4cff /app/workers | |
parent | db06b25376ac7e844e86fb9890fa9f1c2edd2d60 (diff) |
Avoid race condition when streaming deleted statuses (#10280)
* Avoid race condition when streaming deleted statuses * Move redis lock to DistributionWorker to avoid extra Redis value
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/distribution_worker.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/app/workers/distribution_worker.rb b/app/workers/distribution_worker.rb index f423d43ae..4e20ef31b 100644 --- a/app/workers/distribution_worker.rb +++ b/app/workers/distribution_worker.rb @@ -4,7 +4,13 @@ class DistributionWorker include Sidekiq::Worker def perform(status_id) - FanOutOnWriteService.new.call(Status.find(status_id)) + RedisLock.acquire(redis: Redis.current, key: "distribute:#{status_id}") do |lock| + if lock.acquired? + FanOutOnWriteService.new.call(Status.find(status_id)) + else + raise Mastodon::RaceConditionError + end + end rescue ActiveRecord::RecordNotFound true end |