Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tight loop on aborted connection #285

Merged
merged 2 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ use proto::{self, Config, Prioritized};
use bytes::{Buf, Bytes, IntoBuf};
use futures::{self, Async, Future, Poll};
use http::{Request, Response};
use std::{convert, fmt, mem};
use std::{convert, fmt, io, mem};
use std::time::Duration;
use tokio_io::{AsyncRead, AsyncWrite};

Expand Down Expand Up @@ -1045,6 +1045,12 @@ where

while rem > 0 {
let n = try_nb!(self.inner_mut().read(&mut buf[..rem]));
if n == 0 {
return Err(io::Error::new(
io::ErrorKind::ConnectionReset,
"connection closed unexpectedly",
).into());
}

if PREFACE[self.pos..self.pos + n] != buf[..n] {
// TODO: Should this just write the GO_AWAY frame directly?
Expand Down
2 changes: 1 addition & 1 deletion tests/h2-support/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl io::Write for Mock {
let mut me = self.pipe.inner.lock().unwrap();

if me.closed {
return Err(io::Error::new(io::ErrorKind::BrokenPipe, "mock closed"));
return Ok(buf.len());
}

if me.tx_rem == 0 {
Expand Down
16 changes: 16 additions & 0 deletions tests/h2-tests/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,3 +589,19 @@ fn poll_reset_after_send_response_is_user_error() {

srv.join(client).wait().expect("wait");
}

#[test]
fn server_error_on_unclean_shutdown() {
use std::io::Write;

let _ = ::env_logger::try_init();
let (io, mut client) = mock::new();

let srv = server::Builder::new()
.handshake::<_, Bytes>(io);

client.write_all(b"PRI *").expect("write");
drop(client);

srv.wait().expect_err("should error");
}