Node: setInterval not working on Raspberry Pi.

Created on 13 Dec 2015  Â·  29Comments  Â·  Source: nodejs/node

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.

arm stalled timers

Most helpful comment

To confirm. This bug is certainly fixed for node v8.1.2 running on Raspbian GNU/Linux 8 on Raspbery Pi 3.

All 29 comments

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.

This is still an issue in Node 6.9.3 on RPi. Will also try the patch.

Oh yeah, forgot about this. Took my Raspberry Pi 3 days to build Node from source and eventually threw some errors when I tried to run my app, so couldn't test this. Should try to run the test script, but currently no time. Works with the keep-alive interval that triggers console output every ±10 minutes which is ok enough for me at the moment.

Facing the same issue on Raspberry PI 3. Yes, the only work-around so far is having keep-alive interval.
```javascript
setInterval(fn, 30 * 60 * 1000); // your actual interval

setInterval(() => {}, 10 * 60 * 1000) // keep-alive interval
````

Can someone with access to a Raspberry Pi confirm this is still a problem with Node.js 8.x?

Cannot reproduce on RPi3, latest Arch Linux ARM, Kernel 4.9.36, node v8.2.1:

$ node -e 'setInterval (function () { console.log("Tick: "); }, 1000 * 60 * 30);'
Tick:
Tick:

@silverwind can you confirm it fails with v5.2.0 (i.e. negative control)? If it does IMHO we can close this.

Although the code @bnoordhuis is pointing to hasn't changed since v2.30 https://github.com/nodejs/node/pull/1889/files#diff-c2053e03dec17e31a49b19d166265122

Yep, fails with 5.2.0. I think we can safely assume this is fixed.

To confirm. This bug is certainly fixed for node v8.1.2 running on Raspbian GNU/Linux 8 on Raspbery Pi 3.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

addaleax picture addaleax  Â·  3Comments

filipesilvaa picture filipesilvaa  Â·  3Comments

dfahlander picture dfahlander  Â·  3Comments

willnwhite picture willnwhite  Â·  3Comments

seishun picture seishun  Â·  3Comments