Skip to content

Conversation

@LindonAliu
Copy link

Description

Closes: #5520

  • Clean up connection callback contexts on ShutdownComplete so handlers set via ConnectionRef are freed automatically (no leak).
  • Allow connection callbacks to return success when the context was already cleared (e.g., post-cleanup), avoiding panics.
  • Add a regression test that asserts the server-side ConnectionRef handler is dropped after shutdown.
    Testing

Testing

  • cargo test

Documentation

Is there any documentation impact for this change?

@LindonAliu LindonAliu requested a review from a team as a code owner November 21, 2025 23:00
@LindonAliu
Copy link
Author

@microsoft-github-policy-service agree

@codecov
Copy link

codecov bot commented Nov 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@b69aa08). Learn more about missing BASE report.
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5618   +/-   ##
=======================================
  Coverage        ?   85.28%           
=======================================
  Files           ?       60           
  Lines           ?    18663           
  Branches        ?        0           
=======================================
  Hits            ?    15917           
  Misses          ?     2746           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LindonAliu LindonAliu requested a review from guhetier November 22, 2025 12:55
@LindonAliu LindonAliu requested a review from guhetier November 29, 2025 16:02
src/rs/lib.rs Outdated
if !self.handle.is_null() {
// consume the context and drop it after handle close.
let ctx = unsafe { self.get_callback_ctx() };
let ctx = unsafe { self.take_callback_ctx() };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have the same problem as above here.
ListenerClose could potentially trigger notifications (I don't think it currently does, but that might happen in the future). The context needs to stay set until ListenerClose returns.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow-up! I updated the close paths to keep the callback context alive until the Close call returns, so callbacks triggered synchronously during Close still see a valid context:

  • Added peek_callback_ctx (read without clearing).
  • Connection/Listener/Stream now use peek_callback_ctx in close_inner(), call Close, then drop the context after Close returns.

This aligns with the previous behavior you highlighted (context still present during Close) and prevents None when Close fires final notifications without a prior Shutdown.

@LindonAliu LindonAliu requested a review from guhetier December 7, 2025 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unintended handle context leak in Rust

2 participants