-
-
Notifications
You must be signed in to change notification settings - Fork 420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RuleEngine tries to enable UI rules before automation addons have started #3272
Comments
This issue has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/js-scripting-performance-problems-compared-to-nashhorn/142568/4 |
But that is expected behavior and IMO correct. You can create rules with more than one action, one in JS, one in DSL and one ItemCommandAction. If a script engine cannot be created, execution fails and that is logged. There is no way to detect if the scripting add-on is just not started or not installed. a bug would be if that results in OH lock-up (like reported in the forum thread). I can‘t reproduce that. |
The ScriptEngine creation fails because the addon is not loaded yet. |
But as I said: in an OSGi environment there is no guaranteed bundle loading/activation order (except dependencies). But since scripting add-ons are optional we can‘t know which are installed but not yet loaded (or even failing to load). Anyway, I‘ll have a look if we can improve the situation. But I fail to see how that would result in a total lock-up. |
Okay thanks.
This issue is not about the big problem in the community post where openHAB stopped working. |
IMO it's just a decision whether the Rule Engine starts later or the automation addons start earlier. |
I can't reproduce it with the JS scripting add-on installed (maybe my test setup is too small to create significant delays in bundle-loading, but I do see the messages when I uninstall JS scripting. They stop immediately when I install the add-on, so it seems to work as expected. We can't control which bundle is loaded first if we don't know which bundles need to be loaded. If we know that the rule engine needs language 1 and language 2, then we can make it wait for both to be activated (by using ready markers). But that is not the case here: The rule engine can work even if no language is installed at all: there are actions that do not depend on scripting. Besides the log messages (which may be a bit too high with ERROR): is there anything not working as expected? |
I can only sometimes reproduce on my test setup using the following rule: configuration: {}
triggers:
- id: "2"
configuration:
startlevel: 70
type: core.SystemStartlevelTrigger
conditions: []
actions:
- inputs: {}
id: "1"
configuration:
blockSource: <xml xmlns="https://developers.google.com/blockly/xml"><block
type="oh_print" id="rnN_-b6n(g|{_$sj:Q0;" x="144" y="161"><value
name="message"><shadow type="text" id="kV1XotX;Xt%!N?vyRh`i"><field
name="TEXT">Hello world</field></shadow></value></block></xml>
type: application/javascript;version=ECMAScript-2021
script: |
print('Hello world');
type: script.ScriptAction
Yes, I think bundle loading is just too fast on both our test systems, but this issue will definitely occur, because rule engine starts at start level 50 and automation addons have start level 80 (see https://github.com/openhab/openhab-addons/blob/a4a8d5d85f4d3d5ec148bf036255454dbf0a41f0/bundles/org.openhab.automation.jsscripting/src/main/feature/feature.xml#L8).
I undertstand that.
Start level triggers simply don't work for file based rules and you can't use scripts as actions for UI rules with start level triggers. WDYT about changing the start level of automation addons? |
Don't confuse openHAB start levels with OSGi start levels. The start-levels in the The openHAB start-level is totally independent from that and depend on the availability of ready markers that are set by openHAB components when a certain condition is fulfilled. If such a start level is not reached, this does not prevent the bundle from starting, it may only prevent execution of some parts of code. You can see the effect of that if you look at the openHAB start-level of a system where some things fail to load. It's 70 but your scripting add-on works fine. The start-level trigger triggers on openHAB start-levels, not on OSGi start-levels. In
It may make sense to implement #3073, that makes startup more deterministic, but it still does not prevent the error messages. |
Thanks for your explanations, this helps a lot. Also see #3199, this is about problems with start level triggers in JSR223 rules |
It depends on what you want to trigger. I would say that rule execution should be prevented before start level 50 (that is „rule engine ready“). We could try to add ready markers for „all add-ons installed“ (from distribution feature installer and add-on services) to start level 10 (or a new level 15) and then use a bundle tracker that inspects all bundles and sets a ready marker for level 40 when all automation add-ons are active. Not sure if that’s working, but at least an idea. |
Unfortunately I can't test it, because I don't see the issue on my systems, but I'm pretty confident that it works. |
I will see if I can test this, but I can't promise anything, not sure if I can reproduce on my dev system. |
Please note that you need to modify the start-level configuration similar to the attached PR in openhab-distro to see any effect. |
Is this similar/identical to #3073? I wanted to start a discussion about that a while ago, would be great if I finally found people to discuss it with ;) |
It‘s related, but not the same. The difference is that in this case rules can’t run because the scripting engine is not available (or better: they run, it they fail). #3073 is about rules being triggered before the rule engine has finished initialization. And finally #3199 is about missed triggers if rules are added after the start level has already been reached. The common thing is that startup was not really deterministic and I think we‘ll do much better once the PR are merged. I‘m preparing a fix for #3073, too. |
I am not sure what I am doing wrong, but my system hangs a start level 30 because the
I am on the latest 4.0.0-SNAPSHOT ( |
Without the changes from this PR? What happens if you |
nano somehow destroyed the Two things I noticed:
|
If you change the startlevel configuration you need to also add the changes from this PR. |
This PR here: #3275? |
Yes. |
My |
My startup log, the ScriptEngineFactoryBundleTracker seems to recognize the bundle activations:
|
Found it. If the tracker is activated when the ready marker for start level 10 was already set then the ready marker for the script engine factories was never set. |
Great, now openHAB starts again. I have a rule that runs on start level xx and used the Nashorn addon to log hello world, for the different start levels this happens:
I guess I don't need to test start levels > 70. |
One interesting thing I noticed: when I stop openHAB. this is logged:
|
I guess it's more cosmetic, but see my latest commit. |
This now solved as well. thanks 👍 I hope this gets reviewed soon. |
Description
When openHAB starts up, the Rule Engine tries to load and activate UI rules, but fails with
This problem seems to already exist in openHAB 3.4, but it was discovered on the openHAB 4 SNAPSHOTS.
See https://community.openhab.org/t/openhab-4-0-snapshot-discussion/142322/26?u=florian-h05 for NashornJS on openHAB 4.
See https://community.openhab.org/t/js-scripting-performance-problems-compared-to-nashhorn/142568?u=florian-h05 for GraalJS on openHAB 3.4.
Steps To Reproduce
On openHAB 4.0:
Expected behaviour
The Rule Engine should wait for availability of the ScriptEngines provided by automation addons such as NashornJS or GraalJS before attempting to load or run a UI rule.
/cc @J-N-K
The text was updated successfully, but these errors were encountered: