setInterval not working on Raspberry Pi.
A number of people are observing that setInterval is not working for large intervals on the Raspberry Pi.
The following code:
setInterval (function () {
console.log("Tick: ");
}, 1000 * 60 * 30);
Never produces any output for example. (It does work for a 1 minute interval, changing the 30 to a 1 say)
This issue does seem to come and go, some report never seeing it. It's under discussion here: https://www.raspberrypi.org/forums/viewtopic.php?f=34&t=128624
Node version v5.2.0
Operating system: Raspbian Jessie.
Looks similar/identical to https://github.com/nodejs/node/issues/2326
@fivdi Seems to be the same issue and solution I'm using, e.g. an intermediate 20-minute setInterval to keep things from going to sleep.
See https://github.com/node-schedule/node-schedule/issues/218 for the original issue. Thought it was an issue with their library, but turned out the simplest examples and then setInterval didn't work either.
Confirmed. Adding a setInterval with a short period keeps every thing working nicely.
Can one of you run this with debug enabled?
$ NODE_DEBUG=timer node -p "setInterval(function(){console.log('.')}, 1000 * 60 * 30)"
Running it. I have another node process running so perhaps I might have to restart it if it triggers after 30 minutes (haven't tested the issue with 2 non-related node apps using setInterval).
@silverwind This is the only output after running it 24 hours, immediately after entering the command:
{ _called: false,
_idleTimeout: 1800000,
_idlePrev:
Timer {
'0': [Function: listOnTimeout],
_idleNext: [Circular],
_idlePrev: [Circular],
msecs: 1800000 },
_idleNext:
Timer {
'0': [Function: listOnTimeout],
_idleNext: [Circular],
_idlePrev: [Circular],
msecs: 1800000 },
_idleStart: 3942,
_onTimeout: [Function: wrapper],
_repeat: [Function] }
Ah, that's kind of expected. I'm thinking this might be related to a recent v8 upgrade. Not sure what the best debugging steps are, but I'd see if it's reproducible in the d8 shell first.
What kind of Raspberry Pi is it, by the way?
This is on a Pi 2 Model B v1.1.
$ uname -a
Linux raspberrypi 4.1.13-v7+ #826 SMP PREEMPT Fri Nov 13 20:19:03 GMT 2015 armv7l GNU/Linux
$ cat /etc/issue
Raspbian GNU/Linux 8 \n \l
And an original Pi type B :)
Linux raspberrypi 4.1.13+ #826 PREEMPT Fri Nov 13 20:13:22 GMT 2015 armv6l GNU/Linux
Is this still an issue?
@jasnell Yep, still need to use a 10/20-minute timer to prevent it from sleeping, but even that sometimes doesn't work.
@jasnell I can confirm that this issue is also present on Raspberry Pi 3 model B, running OSMC:
osmc@osmc:~$ uname -a
Linux osmc 4.4.6-3-osmc #1 SMP PREEMPT Fri Apr 1 20:55:03 UTC 2016 armv7l GNU/Linux
It's not only setInterval, setTimeout has the same problem.
Tested with Node.js v5.10.1 and v4.4.3.
I can also confirm that this issue is present in node v6.0.0 with Raspbian 8, on Pi 2 model B,
I'm having the same issue on
- RPI b+ with Raspian 7 (Node 6.1)
- RPI 3 with Raspian 8 (Node 4.4.4, 6.0 and 6.1)
http://stackoverflow.com/questions/37153589/long-settimeout-in-nodejs-on-raspberry-pi
Can someone try this patch? See also https://github.com/nodejs/node/issues/2326#issuecomment-128793252.
diff --git a/deps/uv/src/unix/linux-core.c b/deps/uv/src/unix/linux-core.c
index fb8ac3f..8a2693f 100644
--- a/deps/uv/src/unix/linux-core.c
+++ b/deps/uv/src/unix/linux-core.c
@@ -169,7 +169,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
* the value of CONFIG_HZ. The magic constant assumes CONFIG_HZ=1200,
* that being the largest value I have seen in the wild (and only once.)
*/
- static const int max_safe_timeout = 1789569;
+ static const int max_safe_timeout = 6e4;
static int no_epoll_pwait;
static int no_epoll_wait;
struct uv__epoll_event events[1024];
Closing, inactive for > 6 months.
Still an issue though. Not sure how to test that patch…
@sebastiaanluca
$ git clone --depth 1 https://github.com/nodejs/node
$ cd node
$ vim patch # paste patch
$ git apply patch
$ ./configure && make -j $(nproc)
$ ./node -v
@sebastiaanluca did the patch work? @silverwind, maybe I'm not understanding correctly, but wouldn't you want to increase max_safe_timeout rather than decreasing?
@avonmoll I'll look into it this weekend. Needs to run for a while to know for sure.