chiark / gitweb /
otter cli: Use copy_interactive for mgmtchannel proxy
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 1 Jun 2021 12:56:24 +0000 (13:56 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 1 Jun 2021 14:47:10 +0000 (15:47 +0100)
Fixes a buffering-induced deadlock.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otter.rs

index 16494e64f8f163a1febb45ccb0dbd18835780e3b..9359cd7aa4d788c3a2c8e730bb57b35d23764d62 100644 (file)
@@ -1940,12 +1940,19 @@ mod mgmtchannel_proxy {
     let mut write = write.into_stream()?;
 
     let tcmds = thread::spawn(move || {
-      io::copy(&mut io::stdin(), &mut write)
-        .context("copy commands")
+      io_copy_interactive(&mut BufReader::new(io::stdin()), &mut write)
+        .map_err(|e| match e {
+          Left(re)  => AE::from(re).context("read cmds from stdin"),
+          Right(we) => AE::from(we).context("forward cmds to servvr"),
+        })
         .unwrap_or_else(|e| e.end_process(8));
     });
     let tresps = thread::spawn(move || {
-      io::copy(&mut read, &mut io::stdout())
+      io_copy_interactive(&mut read, &mut io::stdout())
+        .map_err(|e| match e {
+          Left(re)  => AE::from(re).context("read resps from server"),
+          Right(we) => AE::from(we).context("forward cmds to stdout"),
+        })
         .context("copy responses")
         .unwrap_or_else(|e| e.end_process(8));
     });