Circular dependancy on edge startup

Did a clean checkout of the official OpenEMS today. I started a clean Edge (without configuration) and I got the following error for several times:

2021-11-19 10:03:53,765 [artLevel] INFO  [org.apache.felix.http.jetty   ] Started Jetty 9.4.43.v20210629 at port(s) HTTP:18080 on context path / [minThreads=8,maxThreads=200,acceptors=1,selectors=4]
2021-11-19 10:03:55,248 [artLevel] WARN  [ntmanager.ComponentManagerImpl] bundle io.openems.edge.core:1.0.0.202111190849 (75)[io.openems.edge.core.componentmanager.ComponentManagerImpl(1)] : Could not get service from ref [io.openems.edge.common.component.ComponentManager, io.openems.edge.common.component.OpenemsComponent, io.openems.edge.common.jsonapi.JsonApi, org.osgi.service.cm.ConfigurationListener]
2021-11-19 10:03:55,249 [artLevel] ERROR [ROOT                          ] bundle org.apache.felix.scr:2.1.30 (163) Circular reference detected trying to get service [io.openems.edge.predictor.api.manager.PredictorManager, io.openems.edge.common.component.OpenemsComponent, io.openems.edge.common.jsonapi.JsonApi]
 stack of references: ServiceReference: [io.openems.edge.predictor.api.manager.PredictorManager, io.openems.edge.common.component.OpenemsComponent, io.openems.edge.common.jsonapi.JsonApi]
ServiceReference: [io.openems.edge.common.component.ComponentManager, io.openems.edge.common.component.OpenemsComponent, io.openems.edge.common.jsonapi.JsonApi, org.osgi.service.cm.ConfigurationListener]

It looks like OSGI has detected a circular depedancy. On the second start I did not get anymore errors and the edge comes up fine. Having a look at the felix console → OSGI → Components I see that the default bundles are active and that all references have been satisfied. It seems that OSGI has solved the circular dependency at some point in time. So I thought I found a hint within the configuration. But I can’t find any references within the configuration.

Just for interest, is there any easy and short explanation what has happend here?
Thanks, Chris

Yes, I came across this before. There are some Circular References in OpenEMS Edge by design, but they are solved according to the specification as being Required from one side and Optional from the oder side. See 112 Declarative Services Specification - OSGi Compendium 7

Circular references must be detected by SCR when it attempts to satisfy component configurations and SCR must fail to satisfy the references involved in the cycle and log an error message with the Log Service, if present. However, if one of the references in the cycle has optional cardinality SCR must break the cycle. The reference with the optional cardinality can be satisfied and bound to zero target services. Therefore the cycle is broken and the other references may be satisfied.

For some reason the ‘Apache Felix Service Component Runtime (SCR)’ still posts this error, even though it is able to solve it properly.

Regards, Stefan

Hi Stefan,
thanks for your detailed explanation and for the refererence to the OSGI Compendium Essentials. Did not know that it was possible to solve this with OSGI. I had such a situation in the past. It was a time consuming pain!
Wish I had known these before.

Regards, Chris

1 Like