msquic icon indicating copy to clipboard operation
msquic copied to clipboard

Unintended handle context leak in Rust

Open nishanthkarthik opened this issue 2 months ago • 1 comments

Describe the bug

The Rust bindings make a distinction between owned and ref types, for instance, Connection and ConnectionRef. On the server side, a listener callback receives a ConnectionRef for the NewConnection event. However, the callback handler attached to a ConnectionRef is not automatically cleaned up internally.

Affected OS

  • [ ] Windows
  • [ ] Linux
  • [ ] macOS
  • [ ] Other (specify below)

Additional OS information

No response

MsQuic version

main

Steps taken to reproduce bug

  1. Modify the example to allocate a large Box<[u8; N]> inside the connection handler closure
  2. Watch the memory usage grow for each new connection

Expected behavior

Setting connection_ref.set_callback_handler(handler) should automatically destroy the handler, if present. For every ConnectionRef, I assume someone owns a Connection internally. This conn: Connection should ideally invoke the cleanup.

Actual outcome

The handler leaks. The example below provides a way to handle this, but I am not sure if this is the idiomatic way to clean up resources.

https://github.com/microsoft/msquic/blob/f7657ad5358c9b3282435de90547053fbd4eb959/src/rs/server_client_test.rs#L162

Additional details

No response

nishanthkarthik avatar Oct 13 '25 02:10 nishanthkarthik

Thanks for reporting this. Our Rust wrappers are a work in progress we haven't had the opportunity to focus on much recently - but a PR is very welcome if you want to give it a try.

guhetier avatar Oct 13 '25 22:10 guhetier