From 915af2a3a85094d7882f8950a557cce62e18530e Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Tue, 11 Oct 2016 19:25:58 -0700 Subject: [PATCH] fix(http): Handle readable in keep-alive It's possible that a connection will be closed and the only way to find out is by doing a read. The keep-alive state (State::Init + Next_::Wait) now tries to read on readable. In the case of EOF, it returns state closed. If bytes are actually available, it's a connection error, and the connection is closed. Otherwise, it's just a spurious wakeup. --- src/http/conn.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/http/conn.rs b/src/http/conn.rs index 3f486c52..c7b57581 100644 --- a/src/http/conn.rs +++ b/src/http/conn.rs @@ -236,6 +236,29 @@ impl> ConnInner { } } }, + State::Init { interest: Next_::Wait, .. } => { + match self.buf.read_from(&mut self.transport) { + Ok(0) => { + // End-of-file; connection was closed by peer + State::Closed + }, + Ok(n) => { + // Didn't expect bytes here! Close the connection. + warn!("read {} bytes in State::Init with Wait interest", n); + State::Closed + }, + Err(e) => match e.kind() { + io::ErrorKind::WouldBlock => { + // This is the expected case reading in this state + state + }, + _ => { + warn!("socket error reading State::Init with Wait interest: {}", e); + State::Closed + } + } + } + }, State::Init { .. } => { trace!("on_readable State::{:?}", state); state