From 1a8e5ccc09a619b3904ec18e6315dd0be710bb98 Mon Sep 17 00:00:00 2001 From: timedout Date: Thu, 17 Sep 2026 00:06:17 +0100 Subject: [PATCH] fix: Gracefully handle extremityless rooms when gapfilling See also: #2259 --- src/service/rooms/event_handler/fetch_prev.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/service/rooms/event_handler/fetch_prev.rs b/src/service/rooms/event_handler/fetch_prev.rs index cf85f10f4..70b12d88c 100644 --- a/src/service/rooms/event_handler/fetch_prev.rs +++ b/src/service/rooms/event_handler/fetch_prev.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, time::Instant}; use conduwuit::{ - Event, PduEvent, debug, debug_info, debug_warn, trace, + Err, Event, PduEvent, debug, debug_info, debug_warn, trace, utils::{BoolExt, IterStream, stream::BroadbandExt}, }; use futures::StreamExt; @@ -45,6 +45,16 @@ pub(super) async fn fetch_prevs( .get_forward_extremities(room_id) .collect::>() .await; + if tail.is_empty() { + // Without any forward extremities, we don't know what the latest + // events are in the room, and consequently have no idea what we + // might be missing. + // + // See also: https://forgejo.ellis.link/continuwuation/continuwuity/issues/2259 + return Err!( + "No forward extremities found in {room_id}, unable to determine horizon" + ); + } let mut gapfilled = self .get_missing_events(