1

I have a NodeJS app that seems to have an infinite loop due to persistent 100% CPU usage - https://github.com/3PG/Bot.

IDE: VSCode

I have changed many files and lines of code since June, but the problem still persists. I believe it is caused by an infinite loop.

How would I detect infinite loops in Node.js for TypeScript project?

ADAMJR
  • 1,880
  • 1
  • 14
  • 34
  • 1
    I think what you are looking for is a profiler: https://stackify.com/node-js-profilers/ Though I havent worked with any here, yet. Just a hint for a direction to look into. – stewo Oct 29 '20 at 11:12
  • check https://stackoverflow.com/questions/12815892/how-to-debug-javascript-when-it-goes-into-infinite-loops-and-recursive-calls-in – The Bomb Squad Nov 04 '20 at 18:12
  • the summary of the answer is in ur loops, just do logging urself.. i assume it's ur code so that'd be ez to do.. so in all ur recursions, have logging – The Bomb Squad Nov 04 '20 at 18:13
  • Infinite loops don't necessarily exhaust the CPU... JS itself runs in an infinite loop called the "Event Loop". Something is trying to do too many computations per unit of time on your machine. As others have mentioned, you'll likely need to profile. Or alternatively, you could do "binary search" on your code - i.e. delete half of the code and see if the problem persists until you find the "half" that contains the bug. – g.delgado Nov 05 '20 at 04:33

1 Answers1

2

I tried setting up your bot to try and replicate the situation. I disabled the API Module, XP Module, Bot Stats module and Music Module so that I could easily set it up without having to do much configuration. As you can see here, I can't replicate your situation as the Bot is running and it's using 0% of the CPU. It may have to do with the specs of your PC, but I can't replicate, so what I suggest to do is try and disabling various modules, so that you can find the one that's causing the CPU to burst.

I hope I helped you ;)

Shqrp
  • 106
  • 4