When the framework is shutdown, components are stopped while some threads using services are still running. This may cause deadlocks in the stopping process.
The shutdown process can't rely on the deployment order. As an example, core storage is deployed after event service because it depends from the event service, but event service should stop processing events before the core storage shutdown.
One way to solve is to put in place some kind of logic, equivalent of the synchronous application started event handling.
The idea is to integrate a new service, that will be in charge of the service passivation. Services will be able to register themselves for being handled before the shutdown. The registering will take in account a priority level. At shutdown time, services will be able to release their resources and forbid others to access them before being stopped.
We need to investigate if their is a standard way of integrating that service with the OSGi framework.