[ 
https://issues.apache.org/jira/browse/FELIX-6069?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17879132#comment-17879132
 ] 

Christoph Läubrich commented on FELIX-6069:
-------------------------------------------

I have an even more strange situation, I changed one component from being 
immediate = false to immediate = true and got the mention error, but this 
component has not any cyclic reference at all:

Component XML
{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}

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
{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}

> You shouldn't use circular references, they are never going to be very 
> reliable.

Actually they work and there are good reasons for them (e.g. listeners), and as 
dynamic  references can come and go anytime it is actually something the 
component has to handle anyways. So any dynamic reference actually "breaks" the 
cycle already.

Sadly I have not found yet a good way to reproduce the error standalone.

> SCR detects cyclic dependency for dynamically bound service
> -----------------------------------------------------------
>
>                 Key: FELIX-6069
>                 URL: https://issues.apache.org/jira/browse/FELIX-6069
>             Project: Felix
>          Issue Type: Bug
>          Components: Declarative Services (SCR)
>    Affects Versions: scr-2.1.14
>            Reporter: Andreas Lemmer
>            Priority: Major
>              Labels: cyclic, scr
>
> Problem case: A bundle with two components: Component1 binds Component2 
> statically, Component2 binds Component1 dynamically. Both components have 
> immediate=true (but changing that also doesn't help).
> When starting the bundle, there is (nearly always) a Framework error message 
> from SCR:
> {{ERROR [org.apache.felix.scr] bundle org.apache.felix.scr:2.1.14 
> (12)Circular reference detected trying to get service [Component1]}}
> {{stack of references: ServiceReference: [Component1]}}
> {{ServiceReference: [Component2]}}
> {{java.lang.Exception: stack trace}}
> {{at 
> org.apache.felix.scr.impl.ComponentRegistry.enterCreate(ComponentRegistry.java:485)}}
> {{at 
> org.apache.felix.scr.impl.BundleComponentActivator.enterCreate(BundleComponentActivator.java:735)}}
> {{at 
> org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:882)}}
> SCR tries it again a few milliseconds later *which works*.
> The real problem here is the error logging indicating that something is not 
> working. This is very disturbing, because the behavior changes from time to 
> time which makes it very hard to see if something is really wrong or if it's 
> just a temporary problem.
> In my opinion, SCR should first start Component2 without Component1, then 
> start Component1 and then bind Component1 to Component2.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to