Timeout on websocket send

This commit is contained in:
Andras Schmelczer 2026-09-22 08:09:19 +01:00
commit c3eb2dbf67
2 changed files with 11 additions and 5 deletions

View file

@ -9,6 +9,7 @@ use crate::{
errors::{SyncServerError, server_error, unauthenticated_error},
server::auth::auth,
};
use crate::consts::WEBSOCKET_SEND_TIMEOUT;
pub struct AuthenticatedWebSocketHandshake {
pub handshake: WebSocketHandshake,
@ -49,9 +50,13 @@ pub async fn send_update_over_websocket(
.context("Failed to serialize update")
.map_err(server_error)?;
sender
.send(Message::Text(serialized_update))
tokio::time::timeout(
WEBSOCKET_SEND_TIMEOUT,
sender.send(Message::Text(serialized_update)),
)
.await
.context("WebSocket send deadline expired")
.map_err(server_error)?
.context("Failed to send message over websocket")
.map_err(server_error)
}

View file

@ -17,6 +17,7 @@ pub const DEFAULT_MAX_CLIENTS_PER_VAULT: usize = 256;
pub const DEFAULT_LOG_DIRECTORY: &str = "logs";
pub const DEFAULT_LOG_ROTATION_INTERVAL: Duration = Duration::from_secs(60 * 60 * 24); // 1 day
pub const DEFAULT_LOG_LEVEL: LogLevel = LogLevel::Info;
pub const WEBSOCKET_SEND_TIMEOUT: Duration = Duration::from_secs(10);
pub const DEFAULT_MERGEABLE_FILE_EXTENSIONS: &[&str] = &["md", "txt"];