From 8f938d97e7f25ca9e8c9ae65f756f952753d9bf7 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 6 Dec 2017 14:50:13 -0800 Subject: [PATCH] fix(conn): handle when pre-emptive flushing closes the write state Closes #1391 --- src/proto/conn.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/proto/conn.rs b/src/proto/conn.rs index 2bcd911a9c..1a2d25d3d8 100644 --- a/src/proto/conn.rs +++ b/src/proto/conn.rs @@ -196,8 +196,9 @@ where I: AsyncRead + AsyncWrite, } }, - Reading::Init | Reading::KeepAlive | Reading::Closed => unreachable!() + _ => unreachable!("read_body invalid state: {:?}", self.state.reading), }; + self.state.reading = reading; ret } @@ -324,6 +325,14 @@ where I: AsyncRead + AsyncWrite, if self.has_queued_body() { try!(self.flush()); + + if !self.can_write_body() { + if chunk.as_ref().map(|c| c.as_ref().len()).unwrap_or(0) == 0 { + return Ok(AsyncSink::NotReady(chunk)); + } else { + return Ok(AsyncSink::Ready); + } + } } let state = match self.state.writing { @@ -369,8 +378,9 @@ where I: AsyncRead + AsyncWrite, } } }, - _ => unreachable!(), + _ => unreachable!("write_body invalid state: {:?}", self.state.writing), }; + self.state.writing = state; Ok(AsyncSink::Ready) }