atagen

macltok

public
Star0
Watch0

Commit a912b21d0811

tarball

atagen <boss@atagen.co>2026-10-28 07:57 UTC

1 file changed+16-2
engine: give the mentions and search services half a second to stop

A sync response the old engine was still processing kept the mentions service busy for 2 to 3.4s after Shutdown, and the reloaded engine can't start until the old one is gone. Past the grace the services are aborted with the other tasks, and the mentions store's single transaction write leaves either the old revision or the new one.
Modified file: src/engine/mod.rs+16 additions−2 deletions
@@ -251,6 +251,20 @@ impl TaskContext {
251251 /// had a 399 room account hand most rooms to the event cache four or five times
252252 const ROOM_LIST_GROWING_BATCH: u32 = 500;
253253
254+/// how long shutdown waits on the mentions and search services before aborting them with the
255+/// other tasks. a sync response still being processed kept mentions busy for 2 to 3.4s, and the
256+/// next engine can't start until this one is gone
257+const SERVICE_STOP_GRACE: std::time::Duration = std::time::Duration::from_millis(500);
258+
259+async fn stop_within(stop: impl Future<Output = ()>, service: &'static str) {
260+ if matrix_sdk::timeout::timeout(stop, SERVICE_STOP_GRACE)
261+ .await
262+ .is_err()
263+ {
264+ tracing::debug!(service, "a service didn't stop in time and is aborted");
265+ }
266+}
267+
254268 /// tasks catch their own panics so each comes back with its context, since joining
255269 /// through the sdk's executor gives no task id to look one up by. wasm has nothing to catch
256270 fn panic_message(payload: Box<dyn std::any::Any + Send>) -> String {
@@ -1242,11 +1256,11 @@ impl Engine {
12421256 self.sync.stop().await;
12431257 if self.mentions_service.is_none() {
12441258 tracing::debug!(step = "mentions", "engine shutdown step");
1245- self.mentions.stop().await;
1259+ stop_within(self.mentions.stop(), "mentions").await;
12461260 }
12471261 if self.search_service.is_none() {
12481262 tracing::debug!(step = "search", "engine shutdown step");
1249- self.search.stop().await;
1263+ stop_within(self.search.stop(), "search").await;
12501264 }
12511265 tracing::debug!(step = "tasks", "engine shutdown step");
12521266 self.tasks.shutdown().await;