StreamRef sends RST_STREAM on drop (#109)

This PR modifies the `Drop` implementation for `StreamRef` to reset the underlying stream if it is the last reference to that stream. Since both `Stream` and `Body` are internally just a `StreamRef`, this means they will both reset the stream on drop; thus, this closes #100.

The assertion that the store no longer contains the dropped stream ID at the end of the `Drop` method  had to be removed, as the stream has to be reset from inside of a `transition` block (which now manages releasing that ID for us), and the `transition` closure moves the value of `stream`, making the assertion no longer possible.

Modifications to some of the tests in `flow_control.rs` were also necessary, in order to prevent `StreamRef`s from being dropped too early.
This commit is contained in:
Eliza Weisman
2017-10-05 18:05:18 -05:00
committed by GitHub
parent ecd2764f4b
commit 2e3dcf602c
9 changed files with 177 additions and 57 deletions

View File

@@ -378,9 +378,12 @@ fn stream_close_by_data_frame_releases_capacity() {
// Send the frame
s2.send_data("hello".into(), true).unwrap();
// Wait for the connection to close
h2.unwrap()
});
// Drive both streams to prevent the handles from being dropped
// (which will send a RST_STREAM) before the connection is closed.
h2.drive(s1)
.and_then(move |(h2, _)| h2.drive(s2))
})
.unwrap();
let srv = srv.assert_client_handshake()
.unwrap()
@@ -446,9 +449,12 @@ fn stream_close_by_trailers_frame_releases_capacity() {
// Send the frame
s2.send_data("hello".into(), true).unwrap();
// Wait for the connection to close
h2.unwrap()
});
// Drive both streams to prevent the handles from being dropped
// (which will send a RST_STREAM) before the connection is closed.
h2.drive(s1)
.and_then(move |(h2, _)| h2.drive(s2))
})
.unwrap();
let srv = srv.assert_client_handshake().unwrap()
// Get the first frame
@@ -527,7 +533,16 @@ fn recv_window_update_on_stream_closed_by_data_frame() {
stream.send_data("hello".into(), true).unwrap();
// Wait for the connection to close
h2.unwrap()
h2.map(|h2| {
// keep `stream` from being dropped in order to prevent
// it from sending an RST_STREAM frame.
std::mem::forget(stream);
// i know this is kind of evil, but it's necessary to
// ensure that the stream is closed by the EOS frame,
// and not by the RST_STREAM.
h2
})
.unwrap()
});
let srv = srv.assert_client_handshake()

View File

@@ -202,7 +202,12 @@ fn send_data_receive_window_update() {
let payload = vec![0; frame::DEFAULT_INITIAL_WINDOW_SIZE as usize];
stream.send_data(payload.into(), true).unwrap();
h2.unwrap()
h2.map(|h2| {
// keep `stream` from being dropped in order to prevent
// it from sending an RST_STREAM frame.
std::mem::forget(stream);
h2
}).unwrap()
});
let mock = mock.assert_client_handshake().unwrap()