Commit 2a24ce5173
Unsigned
Layout: unified · split
src/server.rs +21 −7
| @@ -62,6 +62,7 @@ use std::{ | ||
| 62 | 62 | io::Write, |
| 63 | 63 | path::{Path, PathBuf}, |
| 64 | 64 | rc::{Rc, Weak}, |
| 65 | time::Duration, | |
| 65 | 66 | }; |
| 66 | 67 | use tracing::error; |
| 67 | 68 | use url::Url; |
| @@ -92,6 +93,8 @@ use weechat::{ | ||
| 92 | 93 | Prefix, Weechat, |
| 93 | 94 | }; |
| 94 | 95 | |
| 96 | const JOIN_ROOM_TIMEOUT: Duration = Duration::from_secs(120); | |
| 97 | ||
| 95 | 98 | use crate::{ |
| 96 | 99 | config::ServerBuffer, |
| 97 | 100 | connection::{Connection, InteractiveAuthInfo}, |
| @@ -235,29 +238,40 @@ impl MatrixServer { | ||
| 235 | 238 | let target = room_id_or_alias.to_string(); |
| 236 | 239 | let result = connection |
| 237 | 240 | .spawn(async move { |
| 238 | let servers = | |
| 239 | resolve_alias_servers(&client, &room_id_or_alias).await; | |
| 241 | tokio::time::timeout(JOIN_ROOM_TIMEOUT, async move { | |
| 242 | let servers = | |
| 243 | resolve_alias_servers(&client, &room_id_or_alias).await; | |
| 240 | 244 | |
| 241 | client | |
| 242 | .join_room_by_id_or_alias(&room_id_or_alias, &servers) | |
| 243 | .await | |
| 245 | client | |
| 246 | .join_room_by_id_or_alias(&room_id_or_alias, &servers) | |
| 247 | .await | |
| 248 | }) | |
| 249 | .await | |
| 244 | 250 | }) |
| 245 | 251 | .await; |
| 246 | 252 | |
| 247 | 253 | match result { |
| 248 | Ok(room) => { | |
| 254 | Ok(Ok(room)) => { | |
| 249 | 255 | self.print_network(&format!( |
| 250 | 256 | "Successfully joined room {}", |
| 251 | 257 | room.room_id() |
| 252 | 258 | )); |
| 253 | 259 | } |
| 254 | Err(error) => { | |
| 260 | Ok(Err(error)) => { | |
| 255 | 261 | self.print_error(&format!( |
| 256 | 262 | "Failed to join {}: {}", |
| 257 | 263 | target, |
| 258 | 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 | |