fix: avoid panic when client is confused about rooms

This commit is contained in:
Timo Kösters 2024-02-28 16:24:26 +01:00
parent f4e57fdb22
commit d7fd89df49
No known key found for this signature in database
GPG key ID: 0B25E636FBA7E4CB
3 changed files with 20 additions and 2 deletions

View file

@ -1476,6 +1476,9 @@ pub async fn sync_events_v4_route(
let mut known_subscription_rooms = BTreeSet::new(); let mut known_subscription_rooms = BTreeSet::new();
for (room_id, room) in &body.room_subscriptions { for (room_id, room) in &body.room_subscriptions {
if !services().rooms.metadata.exists(room_id)? {
continue;
}
let todo_room = todo_rooms let todo_room = todo_rooms
.entry(room_id.clone()) .entry(room_id.clone())
.or_insert((BTreeSet::new(), 0, u64::MAX)); .or_insert((BTreeSet::new(), 0, u64::MAX));

View file

@ -331,7 +331,7 @@ fn count_to_id(
.rooms .rooms
.short .short
.get_shortroomid(room_id)? .get_shortroomid(room_id)?
.expect("room exists") .ok_or_else(|| Error::bad_database("Looked for bad shortroomid in timeline"))?
.to_be_bytes() .to_be_bytes()
.to_vec(); .to_vec();
let mut pdu_id = prefix.clone(); let mut pdu_id = prefix.clone();

View file

@ -184,7 +184,22 @@ impl Service {
} }
if errors >= 5 { if errors >= 5 {
break; // Timeout other events
match services()
.globals
.bad_event_ratelimiter
.write()
.unwrap()
.entry((*prev_id).to_owned())
{
hash_map::Entry::Vacant(e) => {
e.insert((Instant::now(), 1));
}
hash_map::Entry::Occupied(mut e) => {
*e.get_mut() = (Instant::now(), e.get().1 + 1)
}
}
continue;
} }
if let Some((pdu, json)) = eventid_info.remove(&*prev_id) { if let Some((pdu, json)) = eventid_info.remove(&*prev_id) {