From 3e91f0b295982278f0541bc0db29366b2c2e88b6 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 5 Dec 2021 08:23:55 -0800 Subject: [PATCH] mux: avoid hanging when ssh domain fails to setup mux server In some cases, the `wezterm cli proxy` subcommand had terminated with error, but the client was still happily waiting for more data to read. This commit spawns a thread to detect the process termination and then drop the child struct when it completes; that in turn causes the stdio descriptors to close and then things tick over. refs: #1358 --- wezterm-client/src/client.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/wezterm-client/src/client.rs b/wezterm-client/src/client.rs index 98406760f..8b5827838 100644 --- a/wezterm-client/src/client.rs +++ b/wezterm-client/src/client.rs @@ -15,6 +15,7 @@ use mux::ssh::ssh_connect_with_ui; use mux::Mux; use openssl::ssl::{SslConnector, SslFiletype, SslMethod}; use openssl::x509::X509; +use portable_pty::Child; use smol::channel::{bounded, unbounded, Receiver, Sender}; use smol::prelude::*; use smol::{block_on, Async}; @@ -317,7 +318,6 @@ struct Reconnectable { struct SshStream { stdin: FileDescriptor, stdout: FileDescriptor, - _child: wezterm_ssh::SshChildProcess, } impl std::fmt::Debug for SshStream { @@ -507,10 +507,19 @@ impl Reconnectable { } }); + // This is a bit gross, but it helps to surface errors in running + // the proxy, and prevents us from hanging forever after the process + // has died + let mut child = exec.child; + std::thread::spawn(move || match child.wait() { + Err(err) => log::error!("waiting on {} failed: {:#}", cmd, err), + Ok(status) if !status.success() => log::error!("{} failed", cmd), + _ => {} + }); + let stream: Box = Box::new(Async::new(SshStream { stdin: exec.stdin, stdout: exec.stdout, - _child: exec.child, })?); self.stream.replace(stream); Ok(())