Rule (timer) make OH3 crash

  • Platform information:
    • Hardware: RPI4

    • OS: Rasbian

    • Java Runtime Environment:
      openjdk version “11.0.9.1” 2020-11-06 LTS
      OpenJDK Runtime Environment Zulu11.43+100-CA (build 11.0.9.1+1-LTS)
      OpenJDK Client VM Zulu11.43+100-CA (build 11.0.9.1+1-LTS, mixed mode)

    • openHAB version: 3.1.0.M3 - Milestone Build (same issue since OH 3.0)

I have a rule with timer. The rule is very basic and have worked fine (OH1 & OH2) until I upgraded to OH3.

The rule is trigger when PIR is detected to turn on a light.
If the PIR is detected and the timer still exist it will just reschedule the timer.
I have put some extra logging in the rule so I can see how much will be executed.

Rule:

rule "Lys bad"

when

    Member of gBadLysPIR changed to ON

then

    if (Alarm_On_Off.state==ON && FerieModus.state == ON){

        sendBroadcastNotification("ALARM! PIR 1. etasje!")

        sendCommand(LysAlarm, ON)

        createTimer(now.plusSeconds(5),  [ |

        sendCommand(E1_PIR_Bad, OFF)

    ])

        

    }

    else

    { 

        if ((triggeringItemName.toString()  == "E1_PIR_Bad")||(now.getHour() <= 10 ||  now.getHour() >= 19))

        {

            logInfo("logg","0")

            var int setBad1LysTimer = 5 

            logInfo("logg","1")

            if((now.getHour() <= 6 ||  now.getHour() >= 23)) {

                 setBad1LysTimer = 2

                 logInfo("logg","3")

            }

            //logInfo("logg","Timer: "+setBad1LysTimer)

            //logInfo("logg","bad1Lys: " + bad1Lys) 

            if(bad1Lystimer === null|| bad1Lystimer.hasTerminated())

            {

                logInfo("logg","4")

                sendCommand(E1_Bad_LED, ON)

                bad1Lystimer = createTimer(now.plusMinutes(setBad1LysTimer), [ |

                sendCommand(E1_Bad_LED, OFF)

                sendCommand(E1_Bad_SPEIL, OFF)

                logInfo("logg","5")

                bad1Lystimer.cancel

                logInfo("logg","6")

                bad1Lystimer = null

                //logInfo("logg","badLysTimer av")

                ])

            }

            else{

                bad1Lystimer.reschedule(now.plusMinutes(setBad1LysTimer))

                logInfo("logg","reschedule badLysTimer :" + setBad1LysTimer)

                logInfo("logg","7")

            }

        }

    createTimer(now.plusSeconds(5),  [ |

        sendCommand(E1_PIR, CLOSED)

        logInfo("logg","8")

        sendCommand(E1_PIR_Bad, OFF)

    ])

    }

end

openhab.log

2021-04-13 21:55:54.378 [INFO ] [org.openhab.core.model.script.logg  ] - 0
2021-04-13 21:55:54.389 [INFO ] [org.openhab.core.model.script.logg  ] - 1
2021-04-13 21:55:54.417 [INFO ] [org.openhab.core.model.script.logg  ] - 4
2021-04-13 21:55:57.750 [INFO ] [org.openhab.core.model.script.logg  ] - 0
2021-04-13 21:55:57.758 [INFO ] [org.openhab.core.model.script.logg  ] - 1
2021-04-13 21:55:57.795 [INFO ] [org.openhab.core.model.script.logg  ] - reschedule badLysTimer :5
2021-04-13 21:55:57.803 [INFO ] [org.openhab.core.model.script.logg  ] - 7

Can you tell us what “make OH3 crash” looks like?
What happens or does not happen that you were not expecting?

I think the behaviour of timer.hasTerminated() is currently buggy inOH3

A circumvention is to have the timer set its own handle variable to null as the last line.

Hi
Thanks for your reply.
When it crash the openhab service is restarting.
For me it seems like the rule is running thru but right after it finished the OH service get restarted.
The “way” I see this is the current log file (both openhab.log and event.log) is been archived and new log file is created. I also see the karaf session is broken and every items/bundle/service is restarting in OH.

Thanks for the hint maybe it’s enough just to check if the timer is null.
I will change the rule and see if it works better.

Never seen anything like that for a simple rule problem.