Cron sometimes doesn't fire

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
piet66
Posts: 59
Joined: 04 Feb 2017 17:00

Cron sometimes doesn't fire

Post by piet66 » 01 Mar 2019 19:58

Sometimes, in rare cases, cron doesn't fire. That's most annoying if heating remains cold or if irrigation is running whole night. It happened to me several times in last months.

One possible reason I found now:
From time to time execution of the timer is delayed for more than one minute. When a cron task has to be executed in this minute, it is skipped.

I proved this by adding some code to cron's index.js (see attached file), which checks this and writes a console message. And indeed I found this message in log file:

Code: Select all

[2019-02-28 20:23:15.092] [I] [core] Cron: tDelta=2 minutes, time reset to last minute +1
Solution may be: instead current minute take last minute + 1. I added this to the attached index.js.

I don't know the reason for these delays. My Raspi3 is only lightly loaded. But it happens. A Raspberry Pi is not a real-time process computer.
Attachments
index.js.zip
(2.12 KiB) Downloaded 6 times
-
Raspberry Pi 3 Model B Rev 1.2
Linux raspberrypi 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux
Raspbian GNU/Linux 8
Z-Way version v2.3.7 from 2018-03-23 09:28:53 +0300 (build b1902d4433d1337bd488834db3347fa7ef8f8a33)

User avatar
PoltoS
Posts: 4536
Joined: 26 Jan 2011 19:36

Re: Cron sometimes doesn't fire

Post by PoltoS » 03 Mar 2019 10:14

It is important to understand why is it blocking for so long. The JS engine is single thread and other threads are all locking each other.

So there should be something slowing down some thread. Do you have blocking HTTP requests or something else running in sync mode?

piet66
Posts: 59
Joined: 04 Feb 2017 17:00

Re: Cron sometimes doesn't fire

Post by piet66 » 03 Mar 2019 12:32

Nothing like that. I have no idea what's the reason.
But I think you always have to expect something like that. Maybe it happens more often without you noticing it. Even if you know the reason, it's not said that you can repair it.
-
Raspberry Pi 3 Model B Rev 1.2
Linux raspberrypi 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux
Raspbian GNU/Linux 8
Z-Way version v2.3.7 from 2018-03-23 09:28:53 +0300 (build b1902d4433d1337bd488834db3347fa7ef8f8a33)

User avatar
PoltoS
Posts: 4536
Joined: 26 Jan 2011 19:36

Re: Cron sometimes doesn't fire

Post by PoltoS » 03 Mar 2019 13:17

In that case we should rather change it to something more generic. It might be delayed to more than 1 minute

piet66
Posts: 59
Joined: 04 Feb 2017 17:00

Re: Cron sometimes doesn't fire

Post by piet66 » 03 Mar 2019 15:31

No problem if you always take last stored minute + 1.
-
Raspberry Pi 3 Model B Rev 1.2
Linux raspberrypi 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux
Raspbian GNU/Linux 8
Z-Way version v2.3.7 from 2018-03-23 09:28:53 +0300 (build b1902d4433d1337bd488834db3347fa7ef8f8a33)

User avatar
PoltoS
Posts: 4536
Joined: 26 Jan 2011 19:36

Re: Cron sometimes doesn't fire

Post by PoltoS » 10 Mar 2019 12:31

And if the delay was two minutes?

piet66
Posts: 59
Joined: 04 Feb 2017 17:00

Re: Cron sometimes doesn't fire

Post by piet66 » 11 Mar 2019 20:46

You are running the loop once per second. If you take each time the last used minute + 1, you will be after n seconds synchronized again, if delay was n minutes.
The trick is to store not the current minute but the last used minute.

Have you looked into my proposal in first post? It should run in this way.
-
Raspberry Pi 3 Model B Rev 1.2
Linux raspberrypi 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux
Raspbian GNU/Linux 8
Z-Way version v2.3.7 from 2018-03-23 09:28:53 +0300 (build b1902d4433d1337bd488834db3347fa7ef8f8a33)

Post Reply