From 16b22bb432b3424000c76870eaf967873047dfd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6sters?= Date: Tue, 3 Nov 2020 21:20:35 +0100 Subject: [PATCH] fix: don't allow more than 50 PDUs in a transaction --- src/database/sending.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/database/sending.rs b/src/database/sending.rs index 33ee5303..597778f2 100644 --- a/src/database/sending.rs +++ b/src/database/sending.rs @@ -54,13 +54,14 @@ impl Sending { )) }) .filter_map(|r| r.ok()) + .filter(|pdu| !pdu.is_empty()) // Skip reservation key + .take(50) + // This should not contain more than 50 anyway { - if !pdu.is_empty() { - current_transactions - .entry(server) - .or_insert_with(Vec::new) - .push(pdu); - } + current_transactions + .entry(server) + .or_insert_with(Vec::new) + .push(pdu); } for (server, pdus) in current_transactions { @@ -95,7 +96,9 @@ impl Sending { .filter_map(|r| r.ok()) .map(|k| { k.subslice(prefix.len(), k.len() - prefix.len()) - }).collect::>(); + }) + .take(50) + .collect::>(); if !new_pdus.is_empty() { for pdu_id in &new_pdus { @@ -108,6 +111,7 @@ impl Sending { futures.push(Self::handle_event(server, new_pdus, &globals, &rooms)); } else { servercurrentpdus.remove(&prefix).unwrap(); + // servercurrentpdus with the prefix should be empty now } } Err((_server, _e)) => {