Christoph Läubrich created FELIX-6724:
-----------------------------------------
Summary: [scr] Cyclic Dependecy reported with activation policy =
lazy
Key: FELIX-6724
URL: https://issues.apache.org/jira/browse/FELIX-6724
Project: Felix
Issue Type: Bug
Reporter: Christoph Läubrich
This was discovered as part of https://issues.apache.org/jira/browse/FELIX-6069
but actually is a bit different case (but maybe even causing this in other
situations)
Assume the following components:
One implements a service in *Bundle B* and the interface is provided by *Bundle
A* and it has *immediate="true"*
{code}
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.4.0"
deactivate="stop" immediate="true" init="1" name="ReceipeAssetHandler">
<service>
<provide interface="AssetHandler"/>
</service>
<implementation class="ReceipeAssetHandler"/>
</scr:component>
{code}
Then in Bundle A (that has activation policy = lazy and provides the service
interface) we have a consumer with dynamic references:
{code}
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
immediate="true" name="Manager">
<service>
<provide interface="Manager"/>
</service>
<reference bind="addListener" cardinality="0..n" interface="Listener"
name="XHandler" policy="dynamic" unbind="removeListener"/>
<reference bind="addAssetHandler" cardinality="0..n"
interface="AssetHandler" name="AssetHandler" policy="dynamic"
unbind="removeAssetHandler"/>
<implementation class="Manager"/>
</scr:component>
{code}
now SCR complains about cyclic dependecy:
{code}
!ENTRY org.apache.felix.scr 4 0 2024-09-04 09:51:52.017
!MESSAGE bundle org.apache.felix.scr:2.2.10 (107) Circular reference detected
trying to get service {AssetHandler}={service.id=107, service.bundleid=22,
service.scope=bundle,
osgi.ds.satisfying.condition.target=(osgi.condition.id=true),
component.name=ReceipeAssetHandler, component.id=36}
stack of references:
ServiceReference: {AssetHandler}={service.id=107, service.bundleid=22,
service.scope=bundle,
osgi.ds.satisfying.condition.target=(osgi.condition.id=true),
component.name=ReceipeAssetHandler, component.id=36}
ServiceReference: {Manager}={service.id=108, service.bundleid=169,
service.scope=bundle,
osgi.ds.satisfying.condition.target=(osgi.condition.id=true),
component.name=Manager, component.id=37}
{code}
*Why this happens:*
As activation of the implementation in *Bundle B* triggers also activation of
the *Bundle A* (due to the classload) *in the same thread* the thread local of
ComponentRegistry#circularInfos already contains *Reference B* (that is
currently activating and has no chance yet to call leaveCreate) while now the
consumer component is created and already "see" the not yet active component
service and try to add it to the list (again) what triggers the error.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)