quinn-rs / quinn

Async-friendly QUIC implementation in Rust
Apache License 2.0
3.76k stars 380 forks source link

connection: wake 'stopped' streams on stream finish events #1458

Closed bmwill closed 1 year ago

bmwill commented 1 year ago

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.

This particular issue can be seen with this type of usage of SendStream::stopped: https://github.com/bmwill/anemo/blob/main/crates/anemo/src/network/request_handler.rs#L170-L177.

This is one such way to fix this memory retention, although it may not be the project's preferred way. Another option would potentially be to remove the waker from the hash map in a Drop impl for the Stopped type.

bmwill commented 1 year ago

Another option would potentially be to remove the waker from the hash map in a Drop impl for the Stopped type.

Given Stopped retains an &mut SendStream internally, i'm thinking that using a Drop impl may actually be a preferable, more foolproof solution.