node icon indicating copy to clipboard operation
node copied to clipboard

setInterval not working on Raspberry Pi.

Open ZiCog opened this issue 10 years ago • 29 comments

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.

ZiCog avatar Dec 13 '15 00:12 ZiCog

Looks similar/identical to https://github.com/nodejs/node/issues/2326

fivdi avatar Dec 13 '15 05:12 fivdi

@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.

sebastiaanluca avatar Dec 13 '15 11:12 sebastiaanluca

Confirmed. Adding a setInterval with a short period keeps every thing working nicely.

ZiCog avatar Dec 13 '15 11:12 ZiCog

Can one of you run this with debug enabled?

$ NODE_DEBUG=timer node -p "setInterval(function(){console.log('.')}, 1000 * 60 * 30)"

silverwind avatar Dec 13 '15 20:12 silverwind

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).

sebastiaanluca avatar Dec 13 '15 22:12 sebastiaanluca

@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] }

sebastiaanluca avatar Dec 14 '15 11:12 sebastiaanluca

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?

silverwind avatar Dec 14 '15 14:12 silverwind

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

ZiCog avatar Dec 17 '15 14:12 ZiCog

And an original Pi type B :)

Linux raspberrypi 4.1.13+ #826 PREEMPT Fri Nov 13 20:13:22 GMT 2015 armv6l GNU/Linux

sebastiaanluca avatar Dec 17 '15 16:12 sebastiaanluca

Is this still an issue?

jasnell avatar Mar 23 '16 05:03 jasnell

@jasnell Yep, still need to use a 10/20-minute timer to prevent it from sleeping, but even that sometimes doesn't work.

sebastiaanluca avatar Mar 23 '16 08:03 sebastiaanluca

@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.

bossie avatar Apr 27 '16 07:04 bossie

I can also confirm that this issue is present in node v6.0.0 with Raspbian 8, on Pi 2 model B,

ZiCog avatar Apr 28 '16 14:04 ZiCog

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

markushedlund avatar May 11 '16 07:05 markushedlund

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];

bnoordhuis avatar May 11 '16 07:05 bnoordhuis

Closing, inactive for > 6 months.

bnoordhuis avatar Feb 07 '17 21:02 bnoordhuis

Still an issue though. Not sure how to test that patch…

sebastiaanluca avatar Feb 07 '17 21:02 sebastiaanluca

@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

silverwind avatar Feb 07 '17 21:02 silverwind

@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 avatar Feb 16 '17 14:02 avonmoll

@avonmoll I'll look into it this weekend. Needs to run for a while to know for sure.

sebastiaanluca avatar Feb 17 '17 10:02 sebastiaanluca