From fadec67fdf1af7fc4426556aea4211f09beea81b Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Thu, 26 Apr 2018 18:20:32 -0700 Subject: [PATCH] prevent a leak of 'active streams' if client request has user error (#266) --- src/proto/streams/streams.rs | 12 ++++++++++-- tests/client_request.rs | 9 +++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/proto/streams/streams.rs b/src/proto/streams/streams.rs index 3ead21c..8c5de28 100644 --- a/src/proto/streams/streams.rs +++ b/src/proto/streams/streams.rs @@ -607,13 +607,21 @@ where let mut stream = me.store.insert(stream.id, stream); - me.actions.send.send_headers( + let sent = me.actions.send.send_headers( headers, send_buffer, &mut stream, &mut me.counts, &mut me.actions.task, - )?; + ); + + // send_headers can return a UserError, if it does, + // we should forget about this stream. + if let Err(err) = sent { + stream.unlink(); + stream.remove(); + return Err(err.into()); + } // Given that the stream has been initialized, it should not be in the // closed state. diff --git a/tests/client_request.rs b/tests/client_request.rs index e785719..433faa3 100644 --- a/tests/client_request.rs +++ b/tests/client_request.rs @@ -440,9 +440,14 @@ fn request_with_connection_headers() { let _ = ::env_logger::try_init(); let (io, srv) = mock::new(); - let srv = srv.assert_client_handshake() + // can't assert full handshake, since client never sends a request, and + // thus never bothers to ack the settings... + let srv = srv.read_preface() .unwrap() - .recv_settings() + .recv_frame(frames::settings()) + // goaway is required to make sure the connection closes because + // of no active streams + .recv_frame(frames::go_away(0)) .close(); let headers = vec![