A platform for community discussion. Free, open, simple.
FIX: avoid race condition creating posts
Samcbd9045c6b88
diff --git a/lib/post_creator.rb b/lib/post_creator.rbindex 9d870736ddd..80f890ddba4 100644--- a/lib/post_creator.rb+++ b/lib/post_creator.rb@@ -325,13 +325,17 @@ class PostCreatorenddef transaction(&blk)- Post.transaction do- if new_topic?+ if new_topic?+ Post.transaction doblk.call- else- # we need to ensure post_number is monotonically increasing with no gaps- # so we serialize creation to avoid needing rollbacks- DistributedMutex.synchronize("topic_id_#{@opts[:topic_id]}", &blk)+ end+ else+ # we need to ensure post_number is monotonically increasing with no gaps+ # so we serialize creation to avoid needing rollbacks+ DistributedMutex.synchronize("topic_id_#{@opts[:topic_id]}") do+ Post.transaction do+ blk.call+ endendendend