mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: avoid race condition creating posts
in some cases the distributed mutex was not protecting us and transactions would fail
This commit is contained in:
parent
2711f173dc
commit
cbd9045c6b
@ -325,13 +325,17 @@ class PostCreator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def transaction(&blk)
|
def transaction(&blk)
|
||||||
Post.transaction do
|
if new_topic?
|
||||||
if new_topic?
|
Post.transaction do
|
||||||
blk.call
|
blk.call
|
||||||
else
|
end
|
||||||
# we need to ensure post_number is monotonically increasing with no gaps
|
else
|
||||||
# so we serialize creation to avoid needing rollbacks
|
# we need to ensure post_number is monotonically increasing with no gaps
|
||||||
DistributedMutex.synchronize("topic_id_#{@opts[:topic_id]}", &blk)
|
# so we serialize creation to avoid needing rollbacks
|
||||||
|
DistributedMutex.synchronize("topic_id_#{@opts[:topic_id]}") do
|
||||||
|
Post.transaction do
|
||||||
|
blk.call
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user