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

Limit AS transactions to 100 events #8606

Merged
merged 4 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/8606.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Appservice transactions are limited to 100 persistent and 100 ephemeral events.
Half-Shot marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 11 additions & 2 deletions synapse/appservice/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@

logger = logging.getLogger(__name__)

MAX_EVENTS_PER_TRANSACTION = 100
Half-Shot marked this conversation as resolved.
Show resolved Hide resolved


class ApplicationServiceScheduler:
""" Public facing API for this module. Does the required DI to tie the
Expand Down Expand Up @@ -136,10 +138,17 @@ async def _send_request(self, service: ApplicationService):
self.requests_in_flight.add(service.id)
try:
while True:
events = self.queued_events.pop(service.id, [])
ephemeral = self.queued_ephemeral.pop(service.id, [])
all_events = self.queued_events.get(service.id, [])
events = all_events[:MAX_EVENTS_PER_TRANSACTION]
del all_events[MAX_EVENTS_PER_TRANSACTION:]
Half-Shot marked this conversation as resolved.
Show resolved Hide resolved

all_events_ephemeral = self.queued_ephemeral.get(service.id, [])
ephemeral = all_events_ephemeral[:MAX_EVENTS_PER_TRANSACTION]
del all_events_ephemeral[MAX_EVENTS_PER_TRANSACTION:]

if not events and not ephemeral:
return

try:
await self.txn_ctrl.send(service, events, ephemeral)
except Exception:
Expand Down