From 4442e8030d403cf891a0ddece0fdb67b9aeaca31 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 14 Jan 2020 22:51:48 -0800 Subject: [PATCH] mux: fix disconnect when a lot of output is dumped to the terminal The root cause and secondary effect were a little surprising: the mux pub/sub notification pipe filled up and because the mux notify routine uses `retain` with the success of the send as a predicate it meant that the full pipe resulted in the muxer killing that end of the subscriber and that in turn made the ClientSession loop fail when it was dispatching a notify on the other end, which terminated the loop and disconnected the client. Now, with this fixed, we have a flow control problem and the terminal will remain busy with ctrl-c not being effective in the mux session. --- src/server/listener.rs | 4 ++-- src/server/pollable.rs | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/server/listener.rs b/src/server/listener.rs index b8bcd8ffd..41b868f9d 100644 --- a/src/server/listener.rs +++ b/src/server/listener.rs @@ -579,7 +579,7 @@ impl ClientSession { Ok(decoded) => { log::trace!("writing pdu with serial {}", decoded.serial); decoded.pdu.encode(&mut self.stream, decoded.serial)?; - self.stream.flush()?; + self.stream.flush().context("while flushing stream")?; } Err(TryRecvError::Empty) => break, Err(TryRecvError::Disconnected) => bail!("ClientSession was destroyed"), @@ -592,7 +592,7 @@ impl ClientSession { MuxNotification::TabOutput(tab_id) => tabs_to_output.insert(tab_id), }, Err(TryRecvError::Empty) => break, - Err(TryRecvError::Disconnected) => bail!("ClientSession was destroyed"), + Err(TryRecvError::Disconnected) => bail!("mux_rx is Disconnected"), }; } diff --git a/src/server/pollable.rs b/src/server/pollable.rs index ab2e1b99d..d3a1a25cb 100644 --- a/src/server/pollable.rs +++ b/src/server/pollable.rs @@ -48,7 +48,11 @@ pub struct PollableSender { impl PollableSender { pub fn send(&self, item: T) -> anyhow::Result<()> { - self.write.lock().unwrap().write_all(b"x")?; + // Attempt to write to the pipe; if it fails due to + // being full, that's fine: it means that the other end + // is going to be signalled already so they won't miss + // anything if our write doesn't happen. + self.write.lock().unwrap().write_all(b"x").ok(); self.sender.send(item).map_err(Error::msg)?; Ok(()) }