Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setInterval not working on Raspberry Pi. #4262

Closed
ZiCog opened this issue Dec 13, 2015 · 29 comments
Closed

setInterval not working on Raspberry Pi. #4262

ZiCog opened this issue Dec 13, 2015 · 29 comments
Labels
arm Issues and PRs related to the ARM platform. stalled Issues and PRs that are stalled. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.

Comments

@ZiCog
Copy link

ZiCog commented Dec 13, 2015

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.

@mscdex mscdex added timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout. arm Issues and PRs related to the ARM platform. labels Dec 13, 2015
@fivdi
Copy link

fivdi commented Dec 13, 2015

Looks similar/identical to #2326

@sebastiaanluca
Copy link

@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 node-schedule/node-schedule#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.

@ZiCog
Copy link
Author

ZiCog commented Dec 13, 2015

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

@silverwind
Copy link
Contributor

Can one of you run this with debug enabled?

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

@sebastiaanluca
Copy link

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
Copy link

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

@silverwind
Copy link
Contributor

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?

@ZiCog
Copy link
Author

ZiCog commented Dec 17, 2015

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

@sebastiaanluca
Copy link

And an original Pi type B :)

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

@jasnell
Copy link
Member

jasnell commented Mar 23, 2016

Is this still an issue?

@sebastiaanluca
Copy link

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

@bossie
Copy link

bossie commented Apr 27, 2016

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

@ZiCog
Copy link
Author

ZiCog commented Apr 28, 2016

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

@Znarkus
Copy link

Znarkus commented May 11, 2016

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

@bnoordhuis
Copy link
Member

Can someone try this patch? See also #2326 (comment).

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

@Fishrock123 Fishrock123 added the stalled Issues and PRs that are stalled. label Sep 17, 2016
@bnoordhuis
Copy link
Member

Closing, inactive for > 6 months.

@sebastiaanluca
Copy link

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

@silverwind
Copy link
Contributor

@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

@avonmoll
Copy link

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

@sebastiaanluca
Copy link

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

@jamesfmackenzie
Copy link

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

@sebastiaanluca
Copy link

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.

@husa
Copy link

husa commented Apr 5, 2017

Facing the same issue on Raspberry PI 3. Yes, the only work-around so far is having keep-alive interval.

setInterval(fn, 30 * 60 * 1000); // your actual interval

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

@silverwind silverwind reopened this Apr 5, 2017
@Trott
Copy link
Member

Trott commented Aug 4, 2017

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

@silverwind
Copy link
Contributor

silverwind commented Aug 5, 2017

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:

@refack
Copy link
Contributor

refack commented Aug 5, 2017

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

@refack
Copy link
Contributor

refack commented Aug 5, 2017

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

@silverwind
Copy link
Contributor

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

@ZiCog
Copy link
Author

ZiCog commented Aug 7, 2017

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

moritzmhmk added a commit to moritzmhmk/SpeedTest that referenced this issue Aug 16, 2017
jfarago added a commit to jfarago/piPower that referenced this issue Nov 5, 2017
- Fixed issue on iphone X where buttons would wrap
- Added keep alive to server to prevent pi from sleeping on old version of node nodejs/node#4262
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arm Issues and PRs related to the ARM platform. stalled Issues and PRs that are stalled. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.
Projects
None yet
Development

No branches or pull requests