Skip to content

ServiceTracker deadlocks if framework is terminated first #913

@tcormackMW

Description

@tcormackMW

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions