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

Commit

Permalink
Limit concurrent AS joins
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston authored and richvdh committed Jun 22, 2018
1 parent 43bb12e commit e5537cf
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
)
from synapse.api.errors import AuthError, SynapseError, Codes
from synapse.types import UserID, RoomID
from synapse.util.async import Linearizer
from synapse.util.async import Linearizer, Limiter
from synapse.util.distributor import user_left_room, user_joined_room


Expand Down Expand Up @@ -68,6 +68,7 @@ def __init__(self, hs):
self.event_creation_hander = hs.get_event_creation_handler()

self.member_linearizer = Linearizer(name="member")
self.member_limiter = Limiter(3)

self.clock = hs.get_clock()
self.spam_checker = hs.get_spam_checker()
Expand Down Expand Up @@ -241,18 +242,23 @@ def update_membership(
):
key = (room_id,)

with (yield self.member_linearizer.queue(key)):
result = yield self._update_membership(
requester,
target,
room_id,
action,
txn_id=txn_id,
remote_room_hosts=remote_room_hosts,
third_party_signed=third_party_signed,
ratelimit=ratelimit,
content=content,
)
as_id = object()
if requester.app_service:
as_id = requester.app_service.id

with (yield self.member_limiter.queue(as_id)):
with (yield self.member_linearizer.queue(key)):
result = yield self._update_membership(
requester,
target,
room_id,
action,
txn_id=txn_id,
remote_room_hosts=remote_room_hosts,
third_party_signed=third_party_signed,
ratelimit=ratelimit,
content=content,
)

defer.returnValue(result)

Expand Down

0 comments on commit e5537cf

Please sign in to comment.