Limit concurrent AS joins (#11996)

Initially introduced in matrix-org-hotfixes by e5537cf (and tweaked by later commits).

Fixes #11995

See also #4826
This commit is contained in:
Brendan Abolivier 2022-02-16 12:16:48 +01:00 committed by GitHub
parent 2b5643b3af
commit 130fd45393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 19 deletions

1
changelog.d/11996.misc Normal file
View File

@ -0,0 +1 @@
Limit concurrent joins from applications services.

View File

@ -82,6 +82,7 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
self.event_auth_handler = hs.get_event_auth_handler() self.event_auth_handler = hs.get_event_auth_handler()
self.member_linearizer: Linearizer = Linearizer(name="member") self.member_linearizer: Linearizer = Linearizer(name="member")
self.member_as_limiter = Linearizer(max_count=10, name="member_as_limiter")
self.clock = hs.get_clock() self.clock = hs.get_clock()
self.spam_checker = hs.get_spam_checker() self.spam_checker = hs.get_spam_checker()
@ -500,6 +501,13 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
key = (room_id,) key = (room_id,)
as_id = object()
if requester.app_service:
as_id = requester.app_service.id
# We first linearise by the application service (to try to limit concurrent joins
# by application services), and then by room ID.
with (await self.member_as_limiter.queue(as_id)):
with (await self.member_linearizer.queue(key)): with (await self.member_linearizer.queue(key)):
result = await self.update_membership_locked( result = await self.update_membership_locked(
requester, requester,