Repository navigation
raspberry pi 300% cpu setTimeout() #49937
Description
Version
v20.7.0
Platform
5.15.61-v7l+ #1579 SMP armv7l GNU/Linux
Subsystem
What steps will reproduce the bug?
The following 3-line script causes high cpu on a raspberry pi4 /CM4 (actively tested on 2 devices, seen on more).
After restarting nodejs a couple of times the issue disappears (the device must be rebooted to consistently get the 300% cpu usage again). Both setInterval and setTimeout show the same behaviour.
After 4-5 minutes, cpu usage drops to normal levels again, until reboot that is.
setInterval(() => {
console.log('test');
}, 20000);
Interval works correctly: 'test' is printed every x seconds
The issue is also present in the following nodejs versions, so it must have been introduced around 18.18.0.
20.7.0 bug
18.18.0 bug
18.17.1 OK!
18.17.0 OK!
18.16.0 OK!
18.14.0: OK!
18.0.0: OK!
16.20.2: OK!
The issue was detected both in a docker container and running nodejs without docker.
Tested both with .deb install and the unoffical builds.
Dockerfile is below.
Dockerfile:
FROM debian:bullseye-slim
WORKDIR /tmp/
RUN set -ex
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN apt-get -y update
RUN apt-get -y --no-install-recommends install ca-certificates
RUN apt-get -y --no-install-recommends install curl
RUN apt-get -y --no-install-recommends install gnupg
RUN apt-get -y --no-install-recommends install libatomic1
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get -y update
RUN apt-get -y --no-install-recommends install nodejs
CMD ["/bin/bash"]
How often does it reproduce? Is there a required condition?
Always after reboot. Starting from versions v18.18.0 up to v20.7.0
Never seen on my desktop, always on RPI devices (rpi4 / CM4)
What is the expected behavior? Why is that the expected behavior?
0% cpu usage, just as in version 16.x
What do you see instead?
300% cpu usage (top -c -H to show threads)
1083 root 20 0 127644 32736 29248 R 99.9 0.4 2:26.74 node bootservertcprelay.js
1085 root 20 0 127644 32736 29248 R 99.9 0.4 2:26.61 node bootservertcprelay.js
1090 root 20 0 127644 32736 29248 R 99.9 0.4 2:26.62 node bootservertcprelay.js
Additional information
Seen also, but very rarely on nodejs version 16.x, so can't confirm it is the same issue.
Please take note that rpi is running a 32-bit kernel...
Activity
aduh95 commentedon Sep 28, 2023
It would be extremely useful to know which version of 20.x introduced the regression.
brubbel commentedon Sep 28, 2023
I have tested that the issue appears between version 18.17.1 and 18.18.0.
Did not do any tests between 18.18.0 and 20.7.0, but I am prepared to do so if that would help?
aduh95 commentedon Sep 28, 2023
If the bug doesn't exist in 18.17.1 but exists in 18.18.0, it's very likely that it was introduced in one of the recent 20.x releases. It would help a lot because 20.x releases will have fewer commits than 18.18.0, so it would be very helpful to help identify which one was it.
brubbel commentedon Sep 28, 2023
node-v20.2.0-linux-armv6l -> OK
node-v20.3.0-linux-armv6l -> bug
https://nodejs.org/en/blog/release/v20.3.0
I suspect this one: bfcb3d1d9a
bnoordhuis commentedon Sep 28, 2023
What do you see when you let
perf toprun for a while in another terminal? I'm interested in the 10 or 20 hottest functions.brubbel commentedon Sep 28, 2023
(This was run without docker, using node-v20.3.0-linux-armv6l)
https://unofficial-builds.nodejs.org/download/release/v20.3.0/node-v20.3.0-linux-armv6l.tar.gz
possibly related: #48654 (comment)
bnoordhuis commentedon Sep 28, 2023
Right, that's a known kernel bug. Upgrade your kernel or set UV_USE_IO_URING=0 in the environment.
brubbel commentedon Sep 28, 2023
~/node-v20.7.0-linux-armv6l/bin $ UV_USE_IO_URING=0 ./node test.jsAwesome, it does the trick!
related: #48444
I suppose this issue can be closed now.
bnoordhuis commentedon Sep 29, 2023
If you can pinpoint the range of affected kernels, I can blacklist them in libuv.
brubbel commentedon Sep 29, 2023
5.15.61-v7l+ (raspberrypi-kernel 1.20220830-1) -> bug
6.1.21-v7l+ (raspberrypi-kernel 1.20230405-1) -> bug
The 6.1.21 kernel was tested using CM4
raspios-bullseye-armhf-lite.imgapt install raspberrypi-kernel.6.1.54-v7l+ (manual kernel update) -> bug
however: in 64bit mode (6.1.54-v8+) -> OK!
So, it is safe to conclude that all 32-bit kernel versions, up to 6.1.54-v7l+ are affected.
I have only tested 64-bit for 6.1.54-v8+ during this complete thread.
Available kernels: https://github.com/raspberrypi/firmware/commits/master
Would the 64-bit not cause other issues with VPN etc, I would be happy to switch :)