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?

4
  • 1
    I think what you are looking for is a profiler: stackify.com/node-js-profilers Though I havent worked with any here, yet. Just a hint for a direction to look into. Commented Oct 29, 2020 at 11:12
  • check stackoverflow.com/questions/12815892/… Commented Nov 4, 2020 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 Commented Nov 4, 2020 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. Commented Nov 5, 2020 at 4:33

1 Answer 1

2
+50

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.