apache / celix

Apache Celix is a framework for C and C++14 to develop dynamic modular software applications using component and in-process service-oriented programming.
https://celix.apache.org/
Apache License 2.0
160 stars 85 forks source link

Deadlock of TEST_F(ShellTestSuite, quitTest) #629

Closed PengZheng closed 10 months ago

PengZheng commented 11 months ago

This issue has been with us for a very long time, though recently it seldom reproduces. https://github.com/apache/celix/commit/b706d163543f403921498b5250244e561ad04298 has fixed a framework reference leak, which could lead to deadlock when shutting down a framework instance.

However, this issue is still not fixed (https://github.com/apache/celix/actions/runs/6032316074/job/16367552785), since its root cause is very special: callCommand(ctx, "quit", true); workes by calling celix_bundleContext_stopBundle/celix_framework_stopBundleAsync via celix_bundleContext_useServiceWithOptions on the framework context to be stopped.

The culprit is the last celix_framework_fireGenericEvent in celix_bundleContext_useServiceWithOptions, which may leak an event carrying a reference to the framework instance, which has no chance to be processed (the event loop has already been stopped).

Note that calling celix_bundleContext_stopBundle/celix_framework_stopBundleAsync via celix_bundleContext_useServiceWithOptions on a normal bundle context is OK. Because celix_bundleActivator_stop of that bundle will synchronize with framework_shutdown.

That said, there is nothing to worry about using quit/stop command via TUI or within any other normal bundle.