From cecef9d402b76af12e6415519deb2b604f77b195 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Tue, 28 Nov 2017 17:13:54 -0800 Subject: [PATCH] fix(client): remove idle connections when read eof is found --- src/proto/conn.rs | 9 +-------- src/proto/dispatch.rs | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/proto/conn.rs b/src/proto/conn.rs index a7573947d8..8f1a32fd51 100644 --- a/src/proto/conn.rs +++ b/src/proto/conn.rs @@ -869,18 +869,11 @@ mod tests { other => panic!("unexpected frame: {:?}", other) } - // client + // client let io = AsyncIo::new_buf(vec![], 1); let mut conn = Conn::<_, proto::Chunk, ClientTransaction>::new(io, Default::default()); conn.state.busy(); - match conn.poll() { - Ok(Async::NotReady) => {}, - other => panic!("unexpected frame: {:?}", other) - } - - // once mid-request, returns the error - conn.state.writing = super::Writing::KeepAlive; match conn.poll() { Err(ref err) if err.kind() == ::std::io::ErrorKind::UnexpectedEof => {}, other => panic!("unexpected frame: {:?}", other) diff --git a/src/proto/dispatch.rs b/src/proto/dispatch.rs index bd7b86caf2..903855418d 100644 --- a/src/proto/dispatch.rs +++ b/src/proto/dispatch.rs @@ -184,11 +184,23 @@ where } fn is_done(&self) -> bool { + trace!( + "is_done; read={}, write={}, should_poll={}, body={}", + self.conn.is_read_closed(), + self.conn.is_write_closed(), + self.dispatch.should_poll(), + self.body_rx.is_some(), + ); let read_done = self.conn.is_read_closed(); - let write_done = self.conn.is_write_closed() || - (!self.dispatch.should_poll() && self.body_rx.is_none()); - read_done && write_done + if !T::should_read_first() && read_done { + // a client that cannot read may was well be done. + true + } else { + let write_done = self.conn.is_write_closed() || + (!self.dispatch.should_poll() && self.body_rx.is_none()); + read_done && write_done + } } }