Znarkus Znarkus - 1 month ago 14
Node.js Question

Long setTimeout in NodeJS on Raspberry PI

I have a weird issue where long setTimeouts don't trigger on Raspberry PI, but they do on Ubuntu/x64 and OSX.

'use strict';

const delay = 1000 * 3600 * 8;
const date = new Date();

date.setTime(new Date().getTime() + delay);
console.log('Alarm set to', date.toString());

setTimeout(function () {
console.log('Alarm!', new Date());
}, delay);


This code will echo
Alarm!
after 8 hours on Ubuntu/x64, but it never triggers on RPI.

Works:


  • Ubuntu/x64

  • OSX



Doesn't work:


  • RPI b+ with Raspian 7 (Node 6.1)

  • RPI 3 with Raspian 8 (Node 4.4.4, 6.0 and 6.1)



According to
ps
the script is in
Sl
state:
Interruptible sleep (waiting for an event to complete), is multi-threaded (using CLONE_THREAD, like NPTL pthreads do).


In a more complex version of this code, where I can control the script through a Web UI, the "alarm" will go off after the set time, but only when I access the Web UI (to wake up the application?).

Is this a NodeJS bug or am I doing something funky?

Answer

Adding this solves it, until the NodeJS issue is fixed.

// Every 20 min to keep awake
setInterval(() => 1, 1000 * 60 * 20);