Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Prevent multiple upgrades on the same room at once #5051

Merged
merged 10 commits into from
Jun 25, 2019
1 change: 1 addition & 0 deletions changelog.d/5051.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent >1 room upgrades happening simultaneously on the same room.
9 changes: 9 additions & 0 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(self, hs):
self.spam_checker = hs.get_spam_checker()
self.event_creation_handler = hs.get_event_creation_handler()
self.room_member_handler = hs.get_room_member_handler()
self.currently_upgrading_rooms = {}

# linearizer to stop two upgrades happening at once
self._upgrade_linearizer = Linearizer("room_upgrade_linearizer")
Expand All @@ -90,6 +91,12 @@ def upgrade_room(self, requester, old_room_id, new_version):

user_id = requester.user.to_string()

if old_room_id in self.currently_upgrading_rooms:
raise SynapseError(
400, "An upgrade for this room is currently in progress."
)
self.currently_upgrading_rooms[old_room_id] = True

with (yield self._upgrade_linearizer.queue(old_room_id)):
# start by allocating a new room id
r = yield self.store.get_room(old_room_id)
Expand Down Expand Up @@ -149,6 +156,8 @@ def upgrade_room(self, requester, old_room_id, new_version):
requester, old_room_id, new_room_id, old_room_state,
)

del self.currently_upgrading_rooms[old_room_id]

defer.returnValue(new_room_id)

@defer.inlineCallbacks
Expand Down