nodejs / nodejs/node

100% CPU usage for a long time after execution of the last statement

Offen
#48,581 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

confirmed-bug v8 engine
Vorherrschende Sprache
JavaScript
Sterne
122k
Forks
37.3k
Ø Merge
4 T. 2 Std.
Gemergte PRs (30 T.)
283

Beschreibung

Version

v12.x-v20.x - severe, v8.x - v10.x - less severe but still visible

Platform

Darwin Andreys-MacBook-Pro.local 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000 arm64

Subsystem

suspect GC

What steps will reproduce the bug?

run first script in the gist: https://gist.github.com/sidorares/128160e6b3dea1da3ad45cd672651d2d#file-repro1-js

After last line console.log("done"); is executed CPU spikes to 100% and stays like that for about 5 minutes.
In case of node v8 and v10 cpu spike is much shorter, 5-7 seconds.
Bun.js executes the script almost instantly

How often does it reproduce? Is there a required condition?

Consistently reproduceable

What is the expected behavior? Why is that the expected behavior?

the script is expected to finish in sub second time

What do you see instead?

CPU spikes for 300-400 seconds which is unexpected for the workload

Additional information

The profiler only reports the code before the CPU spike, no high GC usage, the time after cpu spike is "unaccounted".

 [Shared libraries]:
   ticks  total  nonlib   name
     98    0.0%          /Users/laplace/.nvm/versions/node/v20.3.0/bin/node

 [JavaScript]:
   ticks  total  nonlib   name
      2    0.0%    0.0%  JS: *parseLengthCodedInt /Users/laplace/tmp/2090/repro3.js:2014:24

 [C++]:
   ticks  total  nonlib   name

 [Summary]:
   ticks  total  nonlib   name
      2    0.0%    0.0%  JavaScript
      0    0.0%    0.0%  C++
     66    0.0%    0.0%  GC
     98    0.0%          Shared libraries
  291682  100.0%          Unaccounted

 [C++ entry points]:
   ticks    cpp   total   name

 [Bottom up (heavy) profile]:
  Note: percentage shows a share of a particular caller in the total
  amount of its parent calls.
  Callers occupying less than 1.0% are not shown.

   ticks parent  name
  291682  100.0%  UNKNOWN

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie damit, das erste Skript im verlinkten gist auf den betroffenen Node.js-Versionen auszuführen und sein Verhalten mit Node.js v8-v10 und Bun.js zu vergleichen. Verwenden Sie die gemeldete Profiler-Ausgabe und die Reproduktionszeit, um den CPU-Spike nach console.log zu untersuchen; als abgeschlossen gilt die Arbeit, wenn das Skript in unter einer Sekunde beendet wird, ohne anhaltende CPU-Auslastung.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
node.js
Bereich
backend
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.