Add logic to keep track of COM callbacks and cancel them if the sessi…#40183
Add logic to keep track of COM callbacks and cancel them if the sessi…#40183OneBlue merged 6 commits intofeature/wsl-for-appsfrom
Conversation
…on is terminating
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds tracking of threads that are executing outgoing COM callbacks so that Terminate() can cancel those calls (via CoCancelCall) and avoid session shutdown hangs caused by stuck user callbacks.
Changes:
- Introduces an RAII helper (
UserCOMCallback) to enable COM call cancellation and register/unregister callback threads inWSLCSession. - Cancels outstanding outgoing COM calls during
WSLCSession::Terminate(). - Adds a Windows test that simulates a stuck progress callback and validates it is unblocked by session termination.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| test/windows/WSLCTests.cpp | Adds a regression test for stuck COM progress callback cancellation during Terminate(). |
| src/windows/wslcsession/WSLCSession.h | Adds UserCOMCallback and session APIs/state for tracking callback threads. |
| src/windows/wslcsession/WSLCSession.cpp | Implements callback registration, enables/disables call cancellation, and cancels calls during termination. |
| class UserCOMCallback | ||
| { | ||
| NON_COPYABLE(UserCOMCallback); | ||
|
|
||
| public: | ||
| UserCOMCallback(WSLCSession& Session) noexcept; | ||
| UserCOMCallback(UserCOMCallback&& Other) noexcept; | ||
|
|
||
| ~UserCOMCallback() noexcept; | ||
|
|
||
| UserCOMCallback& operator=(UserCOMCallback&& Other) noexcept; | ||
| void Reset() noexcept; | ||
|
|
||
| private: | ||
| WSLCSession* m_session{}; | ||
| DWORD m_threadId{}; | ||
| }; |
There was a problem hiding this comment.
UserCOMCallback references WSLCSession before WSLCSession is declared in this header. This is a compile error unless there is an earlier forward declaration not shown; add class WSLCSession; before UserCOMCallback (or move UserCOMCallback below the WSLCSession declaration).
JohnMcPMS
left a comment
There was a problem hiding this comment.
This in the CoEnableCallCancellation docs seems concerning:
When call cancellation is enabled on a thread, marshaled synchronous calls from that thread to objects on the same computer can suffer serious performance degradation.
Agreed, although in our case we're not expecting an enormous amount of calls, this is still better than potentially hanging because a client is stuck |
…on is terminating
Summary of the Pull Request
This change adds logic to cancel user COM callbacks when the session terminates. This will prevent a session from being "stuck" if a user callback hangs during termination
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed