-
-
Notifications
You must be signed in to change notification settings - Fork 413
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
Deadlock when an automation/js/….js file is edited too often #3148
Comments
Without the full content of your rules file it is hard to say what is going on. In general the stack trace from CXF is unrelated to rule loading. |
I agree that the problem is not reproducible. Also the stack trace appears seldom, not every time the system stops working, so it might unrelated. OpenHAB 3.3. The deadlock happens, after I do minor edits in the file below and save it, edit, save, edit, save… and at some point there is a deadlock. // /etc/openhab/automation/js/zzz.js
class Rele {
constructor(z) {
this.item = items.getItem(z)
this.name = z
this.manual = items.getItem(z + "_manual")
this.maxItem = items.getItem(z + "_on")
this.minItem = items.getItem(z + "_off")
this.onWatts = items.getItem(z + "_on_watts")
}
get isManual() {
return this.manual.state == "ON"
}
//get isOn() { // NULL is for unknown
// return this.item.state != "OFF"
// }
turn(state) {
this.item.sendCommand(state)
}
}
const releta = ["r1", "r2", "r3", "rk"].map(x => new Rele(x)), load_mode = items.getItem('inv1_Inverter_mode'), volts = items.getItem('inv1_Battery_voltage'), inv1_input_watts = items.getItem('inv1_PV_in_watts'), inv2_input_watts = items.getItem('inv2_PV_in_watts'), unload_mode = items.getItem('inv1_Out_source_priority'), mqtt_broker = actions.get("mqtt", "mqtt:broker:5cc410aefc"), on_watts = {}
let umode = unload_mode.state != "първо 🌞 после 🔋 и накрая ⚛"
releta.forEach(y => on_watts[y.name] = y.onWatts.rawState.intValue())
function execute(data) {
const acc = load_mode.state == "🔋Акумулатор", watts = inv1_input_watts.rawState.intValue() + inv2_input_watts.rawState.intValue()
// if ((data.itemName == "inv1_PV_in_watts" || data.itemName == "inv2_PV_in_watts") && data.newState == "0 W") console.log(data)
for (const x of releta) {
if (!x.isManual) {
const state = x.item.state
if (state == 'ON') {
if (!acc || umode || volts.rawState.floatValue() <= x.minItem.rawState) x.turn('OFF')
} else if (state == 'OFF') {
if (acc && !umode && volts.rawState.floatValue() >= x.maxItem.rawState && watts >= on_watts[x.name]) x.turn('ON')
} else { // state == 'NULL'
x.turn(acc && !umode && volts.rawState.floatValue() > x.minItem.rawState && watts >= on_watts[x.name] ? 'ON' : 'OFF')
}
}
}
}
rules.JSRule({
name: 'Смяна на режима на разреждане',
id: 'change_unload_mode',
triggers: triggers.ItemStateChangeTrigger('inv1_Out_source_priority'),
execute: (data) => {
umode = unload_mode.state != "първо 🌞 после 🔋 и накрая ⚛"
execute(data)
}
})
rules.JSRule({
name: 'Промяна на ватовете за включване',
id: 'on_watt_change',
triggers: releta.map(y => triggers.ItemStateChangeTrigger(y.name + '_on_watts')),
execute: (data) => {
releta.forEach(y => on_watts[y.name] = y.onWatts.rawState.intValue())
execute(data)
}
})
rules.JSRule({
name: 'Автоматично управление',
description: 'Автоматично управление',
id: 'releta_auto',
triggers: [
...releta.map(y => [triggers.ItemStateChangeTrigger(y.name + '_on'),
triggers.ItemStateChangeTrigger(y.name + '_off')]).flat(),
triggers.ItemStateChangeTrigger('inv1_PV_in_watts', null, "0 W"),
triggers.ItemStateChangeTrigger('inv2_PV_in_watts', null, "0 W"),
triggers.ItemStateChangeTrigger('inv1_Battery_voltage'),
triggers.ItemStateChangeTrigger('inv1_Inverter_mode')],
execute: (data) => {
if (data.itemName.endsWith("_on")) {
const y = data.itemName.substring(0, 2), r = releta.find(x => x.name == y)
if (r.maxItem.rawState.floatValue() - r.minItem.rawState.floatValue() < 0.1)
r.minItem.sendCommand(r.maxItem.rawState.floatValue() - 0.1)
} else if (data.itemName.endsWith("_off")) {
const y = data.itemName.substring(0, 2), r = releta.find(x => x.name == y)
if (r.maxItem.rawState.floatValue() - r.minItem.rawState.floatValue() < 0.1)
r.maxItem.sendCommand(r.minItem.rawState.floatValue() + 0.1)
}
execute(data)
}
})
rules.JSRule({
name: 'Зануляване',
id: 'releta_offline',
triggers: releta.map(y => triggers.ItemStateChangeTrigger(y.name + '_online')),
execute: (data) => {
if (data.newState == 'CLOSED') {
const y = data.itemName.substr(0, 3)
for (const x of ["power", "current", "voltage", "temperature"])
items.getItem(y + x).postUpdate('NULL')
const r = data.itemName.substr(0, 2)
items.getItem(r).postUpdate('NULL')
} else {
const r = new Rele(data.itemName.substr(0, 2))
if (!r.isManual)
execute(data)
}
}
})
rules.JSRule({
name: 'Минаване на ръчно/автоматично управление',
id: 'releta_manual',
triggers: releta.map(y => triggers.ItemStateChangeTrigger(y.name + '_manual')),
execute: (data) => {
const t = data.itemName.substr(0, 2) + '/rpc'
if (data.newState == 'ON') {
mqtt_broker.publishMQTT(t, '{"id":10,"src":"S","method":"Script.Stop","params":{"id":1}}')
mqtt_broker.publishMQTT(t, '{"id":11,"src":"T","method":"Script.SetConfig","params":{"id":1,"config":{"enable":false}}}')
} else {
execute(data)
mqtt_broker.publishMQTT(t, '{"id":12,"src":"S","method":"Script.Start","params":{"id":1}}')
mqtt_broker.publishMQTT(t, '{"id":13,"src":"T","method":"Script.SetConfig","params":{"id":1,"config":{"enable":true}}}')
}
}
}) |
I run openHAB on armv7l using openjdk 11.0.16 2022-07-19. According to openhab/openhab-addons#13714 this is incompatible with openHAB 3.4M4, but I am using openHAB 3.3. |
Duplicate of openhab/openhab-addons#12577? |
Yes. So this is not a deadlock, but a memory leak. |
I edit a script /etc/openhab/automation/js/a.js several times, and save now and then the changes. Sometimes the scripts contain syntax errors. Every time the script is saved, openHAB logs:
2022-11-07 12:20:49.295 [INFO ] [rulesupport.loader.ScriptFileWatcher] - Loading script '/etc/openhab/automation/js/a.js'
Usually this is followed by
2022-11-07 12:20:50.677 [INFO ] [org.openhab.automation.script.rules ] - Adding rule: abc
for each rule. But sometimes, the “Adding rule:” message does not appear, the system is stuck, and openHAB 3.3 needs to be stopped and started again.
On another occasion, sometimes after “Loading script …” the system logs:
The duration of 1 minute above after the Loading script and the exception is unusually long, the “Adding rule” messages appear much earlier.
With this exception trace there is also a deadlock, as far as I remember, and the system needs to be restarted.
The complete log for the latter case since the system booted, is:
The text was updated successfully, but these errors were encountered: