microsoft / wil

Windows Implementation Library
MIT License
2.57k stars 234 forks source link

Feature: Add an RAII wrapper to support RPC timeouts when making blocking COM calls #458 #459

Closed dmachaj closed 1 month ago

dmachaj commented 1 month ago

Closes #458

Why is this change being made?

We have a project where we want to make blocking COM calls to another COM server process, but we want protection from the calls taking an infinite amount of time. There is an existing, but very old, wrapper that provides this functionality. Instead of using the old wrapper I am porting it to WIL so that we can use it in a different repo than the original and to share it more broadly because it is useful.

Briefly summarize what changed

Add a new wil::rpc_timeout class to <wil/com.h> along with a few test cases for it. This class uses a combination of CoEnableCallCancellation, CoDisableCallCancellation, and CoCancelCall to provide the COM functionality. CreateThreadpoolTimer is used to provide a timed callback that will not block on the same thread as the blocking COM call.

This object is intended to live on the stack and have a short lifetime. It is single-use and applies to all RPC calls made while it is alive.

How was this change tested?

New test cases in ComTests.cpp.

dunhor commented 1 month ago

I noticed the CppWinRTComServerTests::NotifierAndRegistration failure in other pipeline runs; currently looking at it. This is not a new failure