Skip to content

Commit

Permalink
fix(client): remove idle connections when read eof is found
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Nov 29, 2017
1 parent 9f21241 commit cecef9d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
9 changes: 1 addition & 8 deletions src/proto/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 15 additions & 3 deletions src/proto/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit cecef9d

Please sign in to comment.