1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-09 22:15:15 +03:00

mux: add read and write timeout options for sockets

Adds a default 60 second timeout for read and write for the tls
and unix domain sockets that we create.  This applies to ssh
domains, but not `wezterm ssh` sessions that go direct to ssh ptys.
This commit is contained in:
Wez Furlong 2020-02-01 10:58:02 -08:00
parent e908dee2bc
commit 18a45657be
5 changed files with 32 additions and 0 deletions

View File

@ -844,3 +844,11 @@ fn compute_runtime_dir() -> Result<PathBuf, Error> {
let home = dirs::home_dir().ok_or_else(|| anyhow!("can't find home dir"))?;
Ok(home.join(".local/share/wezterm"))
}
fn default_read_timeout() -> Duration {
Duration::from_secs(60)
}
fn default_write_timeout() -> Duration {
Duration::from_secs(60)
}

View File

@ -1,3 +1,4 @@
use crate::config::*;
use serde::Deserialize;
#[derive(Default, Debug, Clone, Deserialize)]
@ -19,4 +20,7 @@ pub struct SshDomain {
/// If true, connect to this domain automatically at startup
#[serde(default)]
pub connect_automatically: bool,
#[serde(default = "default_read_timeout")]
pub timeout: Duration,
}

View File

@ -67,4 +67,10 @@ pub struct TlsDomainClient {
/// If true, connect to this domain automatically at startup
#[serde(default)]
pub connect_automatically: bool,
#[serde(default = "default_read_timeout")]
pub read_timeout: Duration,
#[serde(default = "default_write_timeout")]
pub write_timeout: Duration,
}

View File

@ -37,6 +37,12 @@ pub struct UnixDomain {
/// on the host NTFS volume.
#[serde(default)]
pub skip_permissions_check: bool,
#[serde(default = "default_read_timeout")]
pub read_timeout: Duration,
#[serde(default = "default_write_timeout")]
pub write_timeout: Duration,
}
impl UnixDomain {

View File

@ -16,6 +16,7 @@ use log::info;
use portable_pty::{CommandBuilder, NativePtySystem, PtySystem};
use promise::{Future, Promise};
use std::collections::HashMap;
use std::convert::TryInto;
use std::io::{Read, Write};
use std::net::TcpStream;
use std::path::Path;
@ -331,6 +332,7 @@ impl Reconnectable {
ui: &mut ConnectionUI,
) -> anyhow::Result<()> {
let sess = ssh_connect_with_ui(&ssh_dom.remote_address, &ssh_dom.username, ui)?;
sess.set_timeout(ssh_dom.timeout.as_secs().try_into()?);
let mut chan = sess.channel_session()?;
@ -414,6 +416,8 @@ impl Reconnectable {
};
ui.output_str("Connected!\n");
stream.set_read_timeout(Some(unix_dom.read_timeout))?;
stream.set_write_timeout(Some(unix_dom.write_timeout))?;
let stream: Box<dyn ReadAndWrite> = Box::new(stream);
self.stream.replace(stream);
Ok(())
@ -476,6 +480,8 @@ impl Reconnectable {
let stream = TcpStream::connect(remote_address)
.with_context(|| format!("connecting to {}", remote_address))?;
stream.set_nodelay(true)?;
stream.set_write_timeout(Some(tls_client.write_timeout))?;
stream.set_read_timeout(Some(tls_client.read_timeout))?;
let stream = Box::new(
connector
@ -537,6 +543,8 @@ impl Reconnectable {
let stream = TcpStream::connect(remote_address)
.with_context(|| format!("connecting to {}", remote_address))?;
stream.set_nodelay(true)?;
stream.set_write_timeout(Some(tls_client.write_timeout))?;
stream.set_read_timeout(Some(tls_client.read_timeout))?;
let stream = Box::new(
connector