When Streams are dropped, close Connection (#221) (#222)

When all Streams are dropped / finished, the Connection was held
open until the peer hangs up. Instead, the Connection should hang up
once it knows that nothing more will be sent.

To fix this, we notify the Connection when a stream is no longer
referenced. On the Connection poll(), we check that there are no
active, held, reset streams or any references to the Streams
and transition to sending a GOAWAY if that is case.

The specific behavior depends on if running as a client or server.
This commit is contained in:
Darren Tsung
2018-02-15 13:14:18 -08:00
committed by Carl Lerche
parent 73b4c03b55
commit 0c59957d88
14 changed files with 193 additions and 45 deletions

View File

@@ -140,9 +140,9 @@ use proto::{self, Config, Prioritized};
use bytes::{Buf, Bytes, IntoBuf};
use futures::{self, Async, Future, Poll};
use http::{Request, Response};
use tokio_io::{AsyncRead, AsyncWrite};
use std::{convert, fmt, mem};
use std::time::Duration;
use tokio_io::{AsyncRead, AsyncWrite};
/// In progress HTTP/2.0 connection handshake future.
///
@@ -424,6 +424,14 @@ where
pub fn poll_close(&mut self) -> Poll<(), ::Error> {
self.connection.poll().map_err(Into::into)
}
/// Sets the connection to a GOAWAY state. Does not close connection immediately.
///
/// This closes the stream after sending a GOAWAY frame
/// and flushing the codec. Must continue being polled to close connection.
pub fn close_connection(&mut self) {
self.connection.close_connection();
}
}
impl<T, B> futures::Stream for Connection<T, B>