context: using a cppmicroservices::ServiceTracker to watch for a service and then relying on either the service becoming resolved or closing the service tracker to unblock the thread.
If the framework is stopped while a ServiceTracker is calling WaitForService with no timeout, the ServiceTracker becomes entirely unusable and deadlocks the program. Close() can't be called on the tracker any more because accessing the bundle context throws, it will never resolve because the framework is gone.
Framework framework = FrameworkFactory().NewFramework();
framework.Start();
ServiceTracker<MyInterfaceOne> tracker(framework.GetBundleContext());
tracker.Open();
auto f = std::async(
[&framework]
{
// technically there's a race here, so the async should ensure WaitForService is started prior to
// terminating the framework.
std::this_thread::sleep_for(std::chrono::seconds(1));
framework.Stop();
framework.WaitForStop(std::chrono::milliseconds::zero());
});
auto const service = tracker.WaitForService();
// unreachable code since it's impossible to unblock WaitForService now
context: using a
cppmicroservices::ServiceTrackerto watch for a service and then relying on either the service becoming resolved or closing the service tracker to unblock the thread.If the
frameworkis stopped while aServiceTrackeris callingWaitForServicewith no timeout, theServiceTrackerbecomes entirely unusable and deadlocks the program.Close()can't be called on the tracker any more because accessing the bundle context throws, it will never resolve because theframeworkis gone.