From a93ed2352f5aa432f1ea6ef85660ba352b514d98 Mon Sep 17 00:00:00 2001 From: Markus Westerlind Date: Sun, 27 Jan 2019 12:31:14 +0100 Subject: [PATCH] fix(std.http): Don't return NotReady if the http stream is broken --- examples/http/main.rs | 45 ++++++++++++++++++++++--------------------- src/http.rs | 9 ++++----- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/examples/http/main.rs b/examples/http/main.rs index 07f231f766..c7c0d47271 100644 --- a/examples/http/main.rs +++ b/examples/http/main.rs @@ -17,7 +17,7 @@ extern crate tokio; use std::{env, fs::File, io::Read}; -use futures::{future, Future}; +use futures::{future, prelude::*}; use gluon::{ new_vm, @@ -74,39 +74,40 @@ mod tests { use std::str; use self::hyper::Client; - use futures::Stream; use tokio::runtime::Runtime; + fn wait_for_server(port: u16) -> impl Future { + let future = + move || Client::new().get(format!("http://localhost:{}", port).parse().unwrap()); + + let retry_strategy = tokio_retry::strategy::FixedInterval::from_millis(400).take(40); + + tokio_retry::Retry::spawn(retry_strategy, future) + .from_err::() + .and_then(|response| { + response + .into_body() + .concat2() + .map(|body| { + assert_eq!(str::from_utf8(&body).unwrap(), "Hello World"); + }) + .from_err::() + }) + } + #[test] fn hello_world() { let mut runtime = Runtime::new().unwrap(); - let port = 12235; + let port = 12234; let thread = new_vm(); let start_server = future::lazy(move || start(&thread, port)); - let future = - move || Client::new().get(format!("http://localhost:{}", port).parse().unwrap()); - - let retry_strategy = tokio_retry::strategy::FixedInterval::from_millis(400).take(40); - runtime .block_on( start_server - .select( - tokio_retry::Retry::spawn(retry_strategy, future) - .from_err::() - .and_then(|response| { - response - .into_body() - .concat2() - .map(|body| { - assert_eq!(str::from_utf8(&body).unwrap(), "Hello World"); - }) - .from_err::() - }), - ) + .select(wait_for_server(port)) .map_err(|(err, _)| err), ) .unwrap_or_else(|err| panic!("{}", err)); @@ -116,7 +117,7 @@ mod tests { fn echo() { let mut runtime = Runtime::new().unwrap(); - let port = 12234; + let port = 12235; let thread = new_vm(); let start_server = future::lazy(move || start(&thread, port)); diff --git a/src/http.rs b/src/http.rs index 6116dba7b0..f44d38946a 100644 --- a/src/http.rs +++ b/src/http.rs @@ -159,17 +159,16 @@ fn write_response( return Ok(Async::NotReady); } Ok(Async::Ready(_)) => (), - Err(_) => { - info!("Could not send http response"); - return Ok(Async::Ready(IO::Value(()))); + Err(err) => { + info!("Could not send http response {}", err); + return Ok(IO::Exception(err.to_string()).into()); } } match sender.send_data(chunk) { Ok(()) => Ok(Async::Ready(IO::Value(()))), Err(chunk) => { - info!("Could not send http response"); unsent_chunk = Some(chunk); - Ok(Async::NotReady) + Ok(IO::Exception("Could not send http response".into()).into()) } } })