From 1122c627c35241eda2e87a9637d3bd5ea19f290c Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Tue, 29 Nov 2022 09:54:56 -0800 Subject: [PATCH] connection: wake 'stopped' streams on stream finish events In the event that the SendStream Stopped future is polled once and then dropped before the remote side has stopped the stream, and instead the stream has been finished, the waker registered in the connection stopped map is never removed and is effectively "leaked" until the connection is closed. This can lead to a large amount of memory being retained when a connection is very long lived and many streams are used over the life of that connection. --- quinn/src/connection.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/quinn/src/connection.rs b/quinn/src/connection.rs index 64c306e91..c812609b8 100644 --- a/quinn/src/connection.rs +++ b/quinn/src/connection.rs @@ -966,6 +966,9 @@ impl State { // If the finishing stream was already dropped, there's nothing more to do. let _ = finishing.send(None); } + if let Some(stopped) = self.stopped.remove(&id) { + stopped.wake(); + } } Stream(StreamEvent::Stopped { id, error_code }) => { if let Some(stopped) = self.stopped.remove(&id) {