Commit 2a24ce5173
Unsigned
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 | }; |
| 66 | use tracing::error; | 67 | use tracing::error; |
| 67 | use url::Url; | 68 | use url::Url; |
| @@ -92,6 +93,8 @@ use weechat::{ | |||
| 92 | Prefix, Weechat, | 93 | Prefix, Weechat, |
| 93 | }; | 94 | }; |
| 94 | 95 | ||
| 96 | const JOIN_ROOM_TIMEOUT: Duration = Duration::from_secs(120); | ||
| 97 | |||
| 95 | use crate::{ | 98 | use 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 | ||