Commit 2a24ce5173

2a24ce51736983c4d7942792593d05e73988f184

parent: e02e5a4787

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-06-30 16:23 UTC
committer: <strk@kbt.io>

fix: time out stalled room joins

Layout: unified · split

src/server.rs +21 −7
@@ -62,6 +62,7 @@ use std::{
62 io::Write, 62 io::Write,
63 path::{Path, PathBuf}, 63 path::{Path, PathBuf},
64 rc::{Rc, Weak}, 64 rc::{Rc, Weak},
65 time::Duration,
65}; 66};
66use tracing::error; 67use tracing::error;
67use url::Url; 68use url::Url;
@@ -92,6 +93,8 @@ use weechat::{
92 Prefix, Weechat, 93 Prefix, Weechat,
93}; 94};
94 95
96const JOIN_ROOM_TIMEOUT: Duration = Duration::from_secs(120);
97
95use crate::{ 98use crate::{
96 config::ServerBuffer, 99 config::ServerBuffer,
97 connection::{Connection, InteractiveAuthInfo}, 100 connection::{Connection, InteractiveAuthInfo},
@@ -235,29 +238,40 @@ impl MatrixServer {
235 let target = room_id_or_alias.to_string(); 238 let target = room_id_or_alias.to_string();
236 let result = connection 239 let result = connection
237 .spawn(async move { 240 .spawn(async move {
238 let servers = 241 tokio::time::timeout(JOIN_ROOM_TIMEOUT, async move {
239 resolve_alias_servers(&client, &room_id_or_alias).await; 242 let servers =
243 resolve_alias_servers(&client, &room_id_or_alias).await;
240 244
241 client 245 client
242 .join_room_by_id_or_alias(&room_id_or_alias, &servers) 246 .join_room_by_id_or_alias(&room_id_or_alias, &servers)
243 .await 247 .await
248 })
249 .await
244 }) 250 })
245 .await; 251 .await;
246 252
247 match result { 253 match result {
248 Ok(room) => { 254 Ok(Ok(room)) => {
249 self.print_network(&format!( 255 self.print_network(&format!(
250 "Successfully joined room {}", 256 "Successfully joined room {}",
251 room.room_id() 257 room.room_id()
252 )); 258 ));
253 } 259 }
254 Err(error) => { 260 Ok(Err(error)) => {
255 self.print_error(&format!( 261 self.print_error(&format!(
256 "Failed to join {}: {}", 262 "Failed to join {}: {}",
257 target, 263 target,
258 format_join_error(&error, &target) 264 format_join_error(&error, &target)
259 )); 265 ));
260 } 266 }
267 Err(error) => {
268 self.print_error(&format!(
269 "Timed out joining {} after {} seconds: {}",
270 target,
271 JOIN_ROOM_TIMEOUT.as_secs(),
272 error
273 ));
274 }
261 } 275 }
262 } 276 }
263 277