smarthomej / addons

SmartHome/J addons for openHAB
Eclipse Public License 2.0
59 stars 23 forks source link

Concurrency issue at startup #411

Closed clinique closed 1 year ago

clinique commented 1 year ago

I observe at startup that some references can be missing :

2022-11-04 15:17:59.953 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/smarthomej/org/smarthomej/automation/javarule/NotificationsForFireTV.java': org.smarthomej.automation.javarule.internal.compiler.CompilerException: /NotificationsForFireTV.java:23: error: cannot find symbol
            Object theBot = actions.get("telegram", Things.notificationsforfiretv_notification_192_168_0_34);
                                                          ^
  symbol:   variable notificationsforfiretv_notification_192_168_0_34
  location: class org.smarthomej.automation.javarule.Things

The symbol notificationsforfiretv_notification_192_168_0_34 seems missing from org.smarthomej.automation.javarule.Items at this point of the startup process (leading the rule class not being loaded).

If I touch the file some seconds later, it works.

I guess that the Thing itself may not be available in the thing registry when javarule-dependency is built. Same thing happens frequently with ThingActions (e.g. Telegram actions).

I think it may be related but I also see this from time to time :

2022-11-04 15:31:33.507 [WARN ] [ule.internal.compiler.JarClassLoader] - Failed to load class 'org.smarthomej.automation.javarule.day.DayEvent' from the stored location '/etc/openhab/automation/lib/java/javarule-dependency.jar': zip END header not found
J-N-K commented 1 year ago

This is hard to solve. The reason is that we can't say if which and if all things are loaded (or we can, if we wait for start level 80) but then we loose the ability to run scripts earlier in the startup process. It's impossible to find out before compiling the script if it makes use of things/actions.

The actions issue is similar, since actions are in an internal package (I don't understand why it was designed that way, since they are intended to be used externally), we have to find out what is available by checking the available actions when they are registered as a service for the first time and then create a sort of wrapper object. This is a limitation in openHAB itself.

It might be possible to prevent re-generation of things/actions dependencies before start-level 80 is reached. WDYT?

clinique commented 1 year ago

Well, from my point of view, I would prefer being sure it starts without errors leaving rules non functional, so delaying the startup of the engine, loosing the ability to run scripts earlier is better tan having the ability to have non functional scripts.

J-N-K commented 1 year ago

Doesn't the rules file re-compile when the dependency changes? For me that is the case.

clinique commented 1 year ago

Yes, it does, during work session. Problems arrive when restarting openHab

clinique commented 1 year ago

Apparently the problem also arrives with the Items class at startup :

2022-11-11 09:43:25.425 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/smarthomej/org/smarthomej/automation/javarule/DayEvents.java': org.smarthomej.automation.javarule.internal.compiler.CompilerException: /DayEvents.java:33: error: cannot access org.smarthomej.automation.javarule.Items
                new Holiday(ir, Items.VacancesScolaires_CurrentEventTitle, Items.VacancesScolaires_NextEventTitle,
                                ^
  bad class file: jar:file:///etc/openhab/automation/lib/java/javarule-dependency.jar!/org/smarthomej/automation/javarule/Items.class
    unable to access file: java.util.zip.ZipException: zip END header not found
    Please remove or make sure it appears in the correct subdirectory of the classpath.
lordjaxom commented 1 year ago

I can confirm this issue. Whenever I restart OpenHAB (i.e. after a power outage) the rules classes don't load right away, leaving most of my home in an unusable state. Touching the Java files some seconds later fixes the problem.

JavaRule 3.2.14 OpenHAB 3.4.0-M4

2022-11-20 13:19:03.630 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/java/org/smarthomej/automation/javarule/user/Sleep.java': org.smarthomej.automation.javarule.internal.compiler.CompilerException: warning: unknown enum constant org.eclipse.jdt.annotation.DefaultLocation.PARAMETER reason: class file for org.eclipse.jdt.annotation.DefaultLocation not found warning: unknown enum constant org.eclipse.jdt.annotation.DefaultLocation.RETURN_TYPE warning: unknown enum constant org.eclipse.jdt.annotation.DefaultLocation.FIELD warning: unknown enum constant org.eclipse.jdt.annotation.DefaultLocation.TYPE_ARGUMENT /Sleep.java:19: error: cannot find symbol @ChannelEventTrigger(channelUID = Things.mqtt_topic_Sleep_Light_Main + ":Button", event = "1") ^ symbol: variable mqtt_topic_Sleep_Light_Main location: class org.smarthomej.automation.javarule.Things

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.